-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathparse.rb
87 lines (69 loc) · 2.17 KB
/
parse.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
require 'nokogiri'
require 'json'
data = []
File.open("cvarlist.html") do |file|
doc = Nokogiri::HTML(file)
doc.search('#cvarTable').each do |a|
first = true
a.xpath('//tr').each do |element|
klass = element.attributes['class']
broken = klass ? klass.value == "broken" : false
# first attribute, hl, cs only?
game = element.children[0].attributes['class']
if game == nil then
game = "base"
else
game = game.text[0..1]
end
# second attribute, single player only?
sp = element.children[1].attributes['class'] ? true : false
# third attribute, cvar name
cvar = element.children[2].text
# forth attribute, default value
default = element.children[3].text
# fith attribute, min value
min = element.children[4].text
# sixth attribute, max value
max = element.children[5].text
# seventh attribute, type
type = element.children[6].text
# eigth attribute, supported on open glide?
ogl = element.children[7].attributes['class'] ? true : false
# ninth attribute, supported on direct 3D?
d3d = element.children[8].attributes['class'] ? true : false
# tenth attribute, supported on software renderer?
sft = element.children[9].attributes['class'] ? true : false
# eleventh attribute, category?
category = element.children[10].text.downcase
# twelth attribute, description
description = element.children[11].text
entry = { }
entry['game'] = game
entry['sp'] = sp
entry['cvar'] = cvar
entry['default'] = default
value = { }
value['min'] = min
value['max'] = max
value['default'] = default
entry['value'] = value
entry['type'] = type
entry['category'] = category
entry['description'] = description
entry['broken'] = broken
if category == 'video'
renderer = { }
renderer['sft'] = sft;
renderer['d3d'] = d3d;
renderer['ogl'] = ogl;
entry['renderer'] = renderer
end
if first then
first = false
else
data.push entry
end
end
end
end
puts data.to_json