Skip to content

Commit

Permalink
bug fix: If there is only 1 entry it will no longer attempt to read f…
Browse files Browse the repository at this point in the history
…urther entries.
  • Loading branch information
James Robertson committed Sep 22, 2015
1 parent 85632c2 commit 95c7a30
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions lib/rowx.rb 100644 → 100755
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion 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']
Expand Down

0 comments on commit 95c7a30

Please sign in to comment.