vdf4r 0.1.3 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/vdf.tt +4 -4
- data/lib/vdf4r/parser.rb +27 -3
- data/lib/vdf4r/version.rb +1 -1
- data/spec/vdf4r/parser_spec.rb +31 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a63a86d02177739416300b7c66a8a6677c0f3b00
|
4
|
+
data.tar.gz: 6f385cfc800ceecab632fbff48e1b48115e2c3b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8ac0be9fc3d5607b3b25cf5b22d42a10f2d87432f81db92397779ab3be153d43a0ce486c685f717f6b322dac722ffb7b47c4baa5a7bd02266adc960b42e8a31
|
7
|
+
data.tar.gz: 276d9bd22b320de3d26d4827c1caf7ec05dc45cf84780266a88e334867b25dfc3b4d76948c792c372a4781cd94d130cb7e7cc2427a801a7fc6a97884be9ba72e
|
data/lib/vdf.tt
CHANGED
@@ -69,23 +69,23 @@ module VDF4R
|
|
69
69
|
end
|
70
70
|
|
71
71
|
rule key_continue_value
|
72
|
-
token_content+ &endline
|
72
|
+
whitespace* token_content+ whitespace* &endline
|
73
73
|
{
|
74
74
|
def value
|
75
75
|
partial_value = elements[1...-1].collect { |e| e.text_value }.join
|
76
76
|
|
77
|
-
[:
|
77
|
+
[:key_continue_value, [partial_value]]
|
78
78
|
end
|
79
79
|
}
|
80
80
|
end
|
81
81
|
|
82
82
|
rule key_exit_value
|
83
|
-
token_content* token_delimiter whitespace* &endline
|
83
|
+
whitespace* token_content* token_delimiter whitespace* &endline
|
84
84
|
{
|
85
85
|
def value
|
86
86
|
partial_value = elements[1...-3].collect { |e| e.text_value }.join
|
87
87
|
|
88
|
-
[:
|
88
|
+
[:key_exit_value, [partial_value]]
|
89
89
|
end
|
90
90
|
}
|
91
91
|
end
|
data/lib/vdf4r/parser.rb
CHANGED
@@ -29,7 +29,7 @@ module VDF4R
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
def parse
|
32
|
+
def parse(keep_only=nil)
|
33
33
|
parser = VDF4R::KeyValuesParser.new
|
34
34
|
store = Store.new
|
35
35
|
key = nil
|
@@ -64,7 +64,19 @@ module VDF4R
|
|
64
64
|
path.pop
|
65
65
|
when :key_value
|
66
66
|
k, v = context
|
67
|
-
|
67
|
+
if keep_only.nil?
|
68
|
+
store_value = true
|
69
|
+
else
|
70
|
+
store_value = false
|
71
|
+
keep_only.each do |keep_key|
|
72
|
+
if (path.include? keep_key or k == keep_key)
|
73
|
+
store_value = true
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
if store_value
|
78
|
+
store.traverse(path)[k] = Parser.dirty(v)
|
79
|
+
end
|
68
80
|
when :key
|
69
81
|
key = context[0]
|
70
82
|
when :key_enter_value
|
@@ -75,7 +87,19 @@ module VDF4R
|
|
75
87
|
when :key_exit_value
|
76
88
|
v = partial_value + "\n#{context[0]}"
|
77
89
|
partial_value = nil
|
78
|
-
|
90
|
+
if keep_only.nil?
|
91
|
+
store_value = true
|
92
|
+
else
|
93
|
+
store_value = false
|
94
|
+
keep_only.each do |keep_key|
|
95
|
+
if (path.include? keep_key or key == keep_key)
|
96
|
+
store_value = true
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
if store_value
|
101
|
+
store.traverse(path)[key] = Parser.dirty(v)
|
102
|
+
end
|
79
103
|
else
|
80
104
|
raise 'unknown node value'
|
81
105
|
end
|
data/lib/vdf4r/version.rb
CHANGED
data/spec/vdf4r/parser_spec.rb
CHANGED
@@ -94,6 +94,25 @@ module VDF4R
|
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
|
+
describe 'selective parsing (items.txt)' do
|
98
|
+
let(:result) do
|
99
|
+
with_fixture('items') do |fixture|
|
100
|
+
subject.new(fixture).parse(keep_only=['item_blades_of_attack'])
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
it "does have item_blades_of_attack" do
|
105
|
+
abilities = result['DOTAAbilities']
|
106
|
+
expect(abilities).to include("item_blades_of_attack")
|
107
|
+
end
|
108
|
+
|
109
|
+
it "doesn't have item_blink" do
|
110
|
+
abilities = result['DOTAAbilities']
|
111
|
+
expect(abilities).not_to include("item_blink")
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
97
116
|
describe 'usage example (dota_english.txt)' do
|
98
117
|
let(:result) do
|
99
118
|
with_fixture('dota_english') do |fixture|
|
@@ -106,6 +125,18 @@ module VDF4R
|
|
106
125
|
result
|
107
126
|
}.not_to raise_error
|
108
127
|
end
|
128
|
+
|
129
|
+
it 'parses multi-line values' do
|
130
|
+
tokens = result['lang']['Tokens']
|
131
|
+
expect(tokens).to include('DOTA_Archronicus_MadMoon_Page4')
|
132
|
+
expect(tokens).to include('npc_dota_hero_rattletrap_bio')
|
133
|
+
|
134
|
+
page_num_lines = tokens['DOTA_Archronicus_MadMoon_Page4'].count("\n") + 1
|
135
|
+
expect(page_num_lines).to eq(3)
|
136
|
+
|
137
|
+
bio_num_lines = tokens['npc_dota_hero_rattletrap_bio'].count("\n") + 1
|
138
|
+
expect(bio_num_lines).to eq(3)
|
139
|
+
end
|
109
140
|
end
|
110
141
|
|
111
142
|
describe 'bad input' do
|