metaheader 1.3beta2 → 1.3beta3

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: 3eb042274d2edc78769525062d7cd315fad33275
4
- data.tar.gz: feb8ef5aff9a4c9829363319b3ab7df601bae43b
3
+ metadata.gz: e4da8975afe832f43e402d8055e6d0b5ffd116b8
4
+ data.tar.gz: 8370402e66dd19c47c31959a1104492b38b680b2
5
5
  SHA512:
6
- metadata.gz: b53340aa50e7f0468e55a217a29eeb6089b39fadc01327836fd3fc214688507d0e8a57c9c061d2a884c8a720661253381421bdd0a46ee84793d65c48823da775
7
- data.tar.gz: a7c9be01c42161999999ecf46b33343c7314ec6116a6719d87843dc298e29443d3f0412c5bb655be266808f0a05e75356d43e4b01a6429a4da651a25d3083a4d
6
+ metadata.gz: 61ed6799668cbd4fea43f71cca2318dfb2f8ec1b9d39bcd4fd02762c63c118d9792eadc4e33ca542e4bdcdd85dafda35af69238719a73c702fe188655472f638
7
+ data.tar.gz: 77fb389959db93f0aa8ceeba8ca188210e18cca144c5bbf8712dd4067a253a86f14e5728de607a11c54a9af6c8873adeef0b935b80dac1b9c81e0b9b3d16840f
@@ -1,4 +1,4 @@
1
1
  class MetaHeader
2
2
  # MetaHeader's version
3
- VERSION = '1.3beta2'.freeze
3
+ VERSION = '1.3beta3'.freeze
4
4
  end
data/lib/metaheader.rb CHANGED
@@ -21,7 +21,7 @@ class MetaHeader
21
21
  @mh
22
22
  end
23
23
 
24
- # @param raw_input [String]
24
+ # @param raw_input [IO]
25
25
  # @return [void]
26
26
  def parse(raw_input)
27
27
  raise NotImplementedError
@@ -63,7 +63,7 @@ class MetaHeader
63
63
  @strict = false
64
64
  @data = {}
65
65
 
66
- @last_key = nil
66
+ @last_tag = nil
67
67
  @empty_lines = 0
68
68
 
69
69
  unless input.is_a? IO
@@ -206,11 +206,11 @@ private
206
206
  line.chomp!
207
207
 
208
208
  # multiline value must have the same line prefix as the key
209
- if @last_key && line.start_with?(@last_prefix.rstrip)
209
+ if @last_tag && line.start_with?(@last_prefix.rstrip)
210
210
  if append line
211
211
  return true
212
212
  else
213
- @last_key = nil
213
+ @last_tag = nil
214
214
  end
215
215
  end
216
216
 
@@ -218,18 +218,26 @@ private
218
218
 
219
219
  return false if @empty_lines > 0
220
220
  return !line.empty? unless match = REGEX.match(line)
221
- return true if match[:alt] && match[:value].nil?
222
221
 
223
222
  # single line
224
223
  @last_prefix = match[:prefix]
225
- key = match[:key].downcase.gsub(/[^\w]/, '_')
226
224
 
227
225
  @raw_value = match[:value]
228
- key, value = parse_value key, @raw_value
226
+ value = parse_value @raw_value
229
227
 
230
- @last_key = key.to_sym
231
- @data[@last_key] = Tag.new match[:key].freeze, value
228
+ @last_tag = Tag.new match[:key].freeze, value
232
229
  @line_breaks = 0
230
+
231
+ # disable implicit values with the alternate syntax
232
+ register @last_tag unless match[:alt] && match[:value].nil?
233
+
234
+ # ok, give me another line!
235
+ true
236
+ end
237
+
238
+ def register(tag)
239
+ key = tag.name.downcase.gsub(/[^\w]/, '_').to_sym
240
+ @data[key] = tag
233
241
  end
234
242
 
235
243
  def append(line)
@@ -247,18 +255,19 @@ private
247
255
  return
248
256
  end
249
257
 
250
- tag = @data[@last_key]
251
- tag.value = @raw_value.to_s unless tag.value.is_a? String
258
+ # add the tag if it uses the alternate syntax and has no value
259
+ register @last_tag
260
+
261
+ @last_tag.value = @raw_value.to_s unless @last_tag.value.is_a? String
252
262
 
253
- @line_breaks += 1 unless tag.value.empty?
254
- tag.value += "\n" * @line_breaks
263
+ @line_breaks += 1 unless @last_tag.value.empty?
264
+ @last_tag.value += "\n" * @line_breaks
255
265
  @line_breaks = @empty_lines = 0
256
266
 
257
- tag.value += stripped
258
- stripped
267
+ @last_tag.value += stripped
259
268
  end
260
269
 
261
- def parse_value(key, value)
270
+ def parse_value(value)
262
271
  case value
263
272
  when 'true'
264
273
  value = true
@@ -270,7 +279,7 @@ private
270
279
  value = nil if value.empty?
271
280
  end
272
281
 
273
- [key, value]
282
+ value
274
283
  end
275
284
 
276
285
  def validate_key(key, rules)
data/test/test_parser.rb CHANGED
@@ -250,6 +250,15 @@ class TestParser < MiniTest::Test
250
250
  assert_nil mh[:chunky]
251
251
  end
252
252
 
253
+ def test_multiline_alternate_syntax
254
+ mh = MetaHeader.new <<-IN
255
+ -- Hello:
256
+ -- World
257
+ IN
258
+
259
+ assert_equal 'World', mh[:hello]
260
+ end
261
+
253
262
  def test_read_file
254
263
  path = File.expand_path '../input/basic_tag', __FILE__
255
264
  mh = MetaHeader.from_file path
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metaheader
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3beta2
4
+ version: 1.3beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - cfillion
@@ -133,4 +133,3 @@ test_files:
133
133
  - test/input/custom_parser
134
134
  - test/test_parser.rb
135
135
  - test/test_validator.rb
136
- has_rdoc: