Class: OpenSRS::XmlProcessor::Libxml

Inherits:
OpenSRS::XmlProcessor show all
Includes:
LibXML::XML
Defined in:
lib/opensrs/xml_processor/libxml.rb

Overview

Libxml

Class Method Summary collapse

Methods inherited from OpenSRS::XmlProcessor

build_element, decode_data, encode_data, encode_dt_array, encode_dt_assoc, parse

Class Method Details

.build(data) ⇒ Object

First, builds REXML elements for the inputted data. Then, it will go ahead and build the entire XML document to send to OpenSRS.



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/opensrs/xml_processor/libxml.rb', line 16

def self.build(data)
  xml = Document.new
  xml.root = envelope = Node.new('OPS_envelope')

  envelope << header = Node.new('header')
  envelope << body = Node.new('body')
  header   << Node.new('version', '0.9')
  body     << data_block = Node.new('data_block')

  data_block << encode_data(data, data_block)

  OpenSRS::SanitizableString.new(xml.to_s, sanitize(xml).to_s)
end

.data_block_element(response) ⇒ Object



44
45
46
47
# File 'lib/opensrs/xml_processor/libxml.rb', line 44

def self.data_block_element(response)
  doc = Parser.string(response).parse
  doc.find('//OPS_envelope/body/data_block/*')
end

.decode_dt_array_data(element) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/opensrs/xml_processor/libxml.rb', line 49

def self.decode_dt_array_data(element)
  dt_array = []

  element.children.each do |item|
    next if item.empty?

    dt_array[item.attributes['key'].to_i] = decode_data(item)
  end

  dt_array
end

.decode_dt_assoc_data(element) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/opensrs/xml_processor/libxml.rb', line 61

def self.decode_dt_assoc_data(element)
  dt_assoc = {}

  element.children.each do |item|
    next if item.content.strip.empty?

    dt_assoc[item.attributes['key']] = decode_data(item)
  end

  dt_assoc
end

.new_element(element_name, _container) ⇒ Object

Accepts two parameters but uses only one; to keep the interface same as other xml parser classes Is that a side effect of Template pattern?



76
77
78
# File 'lib/opensrs/xml_processor/libxml.rb', line 76

def self.new_element(element_name, _container)
  Node.new(element_name.to_s)
end