-
Notifications
You must be signed in to change notification settings - Fork 0
/
converter.rb
140 lines (121 loc) · 2.59 KB
/
converter.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
require 'oga'
require 'erb'
require 'net/https'
require 'fileutils'
module Effects
class Effect
Template = ERB.new File.read("effect.erb")
def initialize(spell)
@spell = spell
end
def xml
@spell.to_s
end
def attributes()
@spell.attributes.reject {|prop| %w(name number).include?(prop.name)}
end
def name()
@spell.get("name")
end
def number()
@spell.get("number")
end
def circle_number()
num = self.number.to_s
return num.slice(0...1) if num.size.eql?(3)
return num.slice(0...2)
end
def circle()
case self.circle_number.to_i
when 1
:minor_spirit
when 2
:major_spirit
when 3
:cleric
when 4
:minor_elemental
when 5
:major_elemental
when 6
:ranger
when 7
:sorcerer
when 9
:wizard
when 10
:bard
when 11
:empath
when 12
:minor_mental
when 16
:paladin
when 17
:arcane
when 97
:guardians_of_sunfist
when 98
:order_of_voln
when 99
:council_of_light
when 66
:environment
when 19
:whale
when 94, 95, 96
:psm
else
:unknown
end
end
def costs()
@spell.css("cost")
end
def duration
@spell.css("duration")
end
def start_messages
@spell.css(%`message[type="start"]`).map(&:text)
end
def end_messages
@spell.css(%`message[type="end"]`).map(&:text)
end
def file_name()
File.join self.dir, (self.number + "-" + self.name.downcase)
.gsub("\s", "-")
.gsub("(", "")
.gsub(")", "")
.gsub("'", "")
.gsub("aa:", "assume-aspect")
.gsub(%r[-{1,}], "-")
.strip + ".rb"
end
def dir()
File.join "effects", self.circle.to_s
end
def render()
Effect::Template.result_with_hash(effect: self)
end
def write()
FileUtils.mkdir_p(self.dir)
File.open(self.file_name, "w") {|f| f << Converter.normalize_whitespace(self.render) }
end
end
end
module Effects
module Converter
def self.normalize_whitespace(string)
string.gsub(/\s+\n{1,}/, "\n")
end
def self.main()
@document = Oga.parse_html File.read("./spell-list.xml")
@effects = @document.css("spell").map do |spell| Effect.new(spell) end
@effects.each(&:write)
#spell = @effects.find {|e| e.number == "101"}
#puts spell.xml
#puts spell.start_messages
end
Converter.main()
end
end