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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7a09a7af158491d41e544601f8a672a2fdb23ae1
4
- data.tar.gz: 88053df30f73d3e41e7ec671793d7e22ca709848
3
+ metadata.gz: a63a86d02177739416300b7c66a8a6677c0f3b00
4
+ data.tar.gz: 6f385cfc800ceecab632fbff48e1b48115e2c3b1
5
5
  SHA512:
6
- metadata.gz: eed8929b97c8279ce42811f5d78e102a402f2a9e574aaf4a20045de6400a3de43b8feb9cdd7e4c7705275854fded4c8b6da50d26ddd24760e2c81c43dbb35f0b
7
- data.tar.gz: d76015eeebcfbd8fb52fae8984397df910a28801eccb124fd1ee523ac9de609e450105d5206d1e1658c1536aa32de8d64074ae38572e1408ba6dbe8276bc0f9d
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
- [:key_enter_value, [partial_value]]
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
- [:key_enter_value, [partial_value]]
88
+ [:key_exit_value, [partial_value]]
89
89
  end
90
90
  }
91
91
  end
@@ -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
- store.traverse(path)[k] = Parser.dirty(v)
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
- store.traverse(path)[k] = Parser.dirty(v)
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
@@ -1,3 +1,3 @@
1
1
  module VDF4R
2
- VERSION = '0.1.3'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vdf4r
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Morris