-
Notifications
You must be signed in to change notification settings - Fork 0
/
powers.rb
41 lines (41 loc) · 918 Bytes
/
powers.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
require 'find'
require 'nokogiri'
require 'open-uri'
p = ""
id = 0;
Find.find('./') do |f|
if File.file?(f) && f =~ /powers-power/
p << "{'id': '#{id.to_s}',"
id=id+1
dis = false
doc = Nokogiri::HTML(open(f))
doc.css('d1 font > *').each do |n|
c = n.content.gsub(/"/,'"').gsub(/\n/,'<br>')
if n.to_s.match(/<h1>/)
p << "'name': \"#{c}\", "
end
if n.to_s.match(/<dt>/) && !n.to_s.match(/<h1>/)
p << "'#{c[0..-2]}': "
end
if n.to_s.match(/<dd>/)
p << "\"#{c}\", "
end
if dis
arr = c.split
p << "'class': \"#{arr[0]}\", 'level': \"#{arr[-1]}\", "
dis = false
end
if n.to_s.match(/<dt><b>Display/)
dis = true
end
end
p = p[0..-3]
p << "},"
# puts p
end
File.open('powers.js', 'w') do |o|
o.puts 'powers = ['
o.puts p
o.puts ']'
end
end