From 95c7a30abbd8240748ebb831b0ae7a36566987d0 Mon Sep 17 00:00:00 2001 From: James Robertson Date: Tue, 22 Sep 2015 12:26:09 +0100 Subject: [PATCH] bug fix: If there is only 1 entry it will no longer attempt to read further entries. --- lib/rowx.rb | 11 ++++++++--- rowx.gemspec | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) mode change 100644 => 100755 lib/rowx.rb diff --git a/lib/rowx.rb b/lib/rowx.rb old mode 100644 new mode 100755 index 155a25f..08208b3 --- a/lib/rowx.rb +++ b/lib/rowx.rb @@ -28,20 +28,25 @@ def initialize(txt, level: nil) a = LineTree.new(txt.gsub(/^-*$/m,''), \ level: level, ignore_blank_lines: false).to_a + keyfield = a[0][0][/\w+:/]; i = 0 # find the keyfield. if there's only 1 keyfield in all of the rows it's # not a keyfield. Keep searching until all rows have been searched - while a.select {|x| x[0][/^#{keyfield}/]}.length <= 1 and i < a.length + while a.select {|x| x[0][/^#{keyfield}/]}.length <= 1 and \ + i < a.length and a[i+1] + i += 1 - keyfield = a[i][0][/\w+/] - end + keyfield = a[i][0][/\w+/] + + end keyfield = a[0][0][/\w+/] if i == a.length - 1 records = a[i..-1].collate { |x| x.first =~ /^#{keyfield }/ } summary = scan_a a.slice!(0,i) summary[0] = 'summary' + @to_a = ['root', {}] + [summary] + scan_records(records, level) @to_xml = Rexle.new(@to_a).xml pretty: true diff --git a/rowx.gemspec b/rowx.gemspec index 8ead70c..d797017 100644 --- a/rowx.gemspec +++ b/rowx.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'rowx' - s.version = '0.4.1' + s.version = '0.4.2' s.summary = 'rowx' s.description = 'Generates XML from rows of labelled, nested, and plain text' s.authors = ['James Robertson']