Class: RowX

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(txt) ⇒ 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
# File 'lib/rowx.rb', line 27

def initialize(txt)

  a = LineTree.new(txt.gsub(/^-*$/m,'')).to_a
   
  keyfield = a[0][0][/\w+/]; i = 0

  while a.select {|x| x[0][/#{keyfield}/]}.length <= 1 and i < a.length
    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)    
  @to_xml = Rexle.new(@to_a).xml pretty: true

end

Instance Attribute Details

#to_aObject (readonly)

Returns the value of attribute to_a.



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

def to_a
  @to_a
end

#to_xmlObject (readonly)

Returns the value of attribute to_xml.



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

def to_xml
  @to_xml
end