Class: PxRowX

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

Instance Method Summary collapse

Constructor Details

#initialize(txt, record_name: 'item') ⇒ PxRowX

Returns a new instance of PxRowX.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/pxrowx.rb', line 11

def initialize(txt, record_name: 'item')

  @record_name = record_name
  
  lt = LineTree.new(txt)
  a = lt.to_a

  labels = []

  i = 0
  label = a[i][0][/^\w+/]

  while (not labels.include?(label)) and i < a.length do

    labels << label
    i+=1
    label = a[i][0][/^\w+/]

  end

  r = scan_tree labels.length, a
  rows = make_rows r

  ['items', {}, nil].reverse.each {|x| rows.unshift x}
  
  h = {
    title: '',
    recordx_type: 'polyrex',
    schema: "items[title]/#{@record_name}[#{labels.join(', ')}]"
  }

  summary = RexleBuilder.new(h, debug: false).to_a
  summary[0] = 'summary'
  rows.insert 3, summary
  
  @doc = Rexle.new(rows)
  
end

Instance Method Details

#to_xml(options = {}) ⇒ Object



50
51
52
# File 'lib/pxrowx.rb', line 50

def to_xml(options={})
  @doc.xml options
end