Class: RowX

Inherits:
Object
  • Object
show all
Defined in:
lib/rowx.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(txt, level: nil) ⇒ RowX

Returns a new instance of RowX.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rowx.rb', line 27

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 and a[i+1]
    
    i += 1
    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

end

Instance Attribute Details

#to_a ⇒ Object (readonly)

Returns the value of attribute to_a.



25
26
27
# File 'lib/rowx.rb', line 25

def to_a
  @to_a
end

#to_xml ⇒ Object (readonly)

Returns the value of attribute to_xml.



25
26
27
# File 'lib/rowx.rb', line 25

def to_xml
  @to_xml
end