Class: PolyrexBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/polyrex-builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(rows = [], parents: [], summary: {}, rootname: 'items') ⇒ PolyrexBuilder

Returns a new instance of PolyrexBuilder.



13
14
15
16
17
18
19
20
21
22
# File 'lib/polyrex-builder.rb', line 13

def initialize(rows=[], parents: [], summary: {}, rootname: 'items')

  records = rows.map {|x|  pxify(x, parents) }
  
  summary.merge!({recordx_type: 'polyrex'})
  h = {rootname.to_sym => {summary: summary, records: records }}

  @a = RexleBuilder.new(h).to_a[3]

end

Instance Method Details

#to_aObject



24
25
26
# File 'lib/polyrex-builder.rb', line 24

def to_a()
  @a
end

#to_xmlObject



28
29
30
31
32
33
34
35
# File 'lib/polyrex-builder.rb', line 28

def to_xml()  
  
  doc = Rexle.new(@a)
  schema = PolyrexSchema.new.parse(doc.root.xml).to_schema    
  doc.root.element('summary').add Rexle::Element.new('schema').add_text(schema)
  
  doc.xml pretty: true    
end