class PxLite

Attributes

records[RW]
summary[RW]

Public Class Methods

new(location=nil, schema: nil) click to toggle source
# File lib/pxlite.rb, line 14
def initialize(location=nil, schema: nil)

  @schema = schema
  @summary, @records  = {}, []

  return @schema = location if location[/\[/]
  s, _ = RXFReader.read location

  if s then
    parse xml=s
  end

end

Public Instance Methods

to_xml() click to toggle source
# File lib/pxlite.rb, line 28
def to_xml()

  rootname = @schema[/\w+/]
  parents =  @schema.scan(/\w+(?=\[)/).map(&:to_sym)

  pb = PolyrexBuilder.new(@records, parents: parents,
                          summary: summary, rootname: rootname)
  pb.to_xml

end

Private Instance Methods

parse(xml) click to toggle source
# File lib/pxlite.rb, line 41
def parse(xml)

  @summary, @records = scan(Rexle.new(xml).root)
  @schema = @summary[:schema]

end
scan(node) click to toggle source
# File lib/pxlite.rb, line 48
def scan(node)

  summary = node.xpath('summary/*').map {|x| [x.name.to_sym, x.text]}.to_h
  records = node.xpath('records/*').map {|x| scan x}

  if records.any? then
    [summary, records]
  else
    [summary]
  end

end