Class: EdifactConverter::EDI2XML11::XmlHandler::XmlElement

Inherits:
Object
  • Object
show all
Defined in:
lib/edifact_converter/edi2xml11/xml_handler.rb

Constant Summary collapse

ATTRIBUTES =
[:name, :children, :text, :position, :parent, :position, :hidden]

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ XmlElement

Returns a new instance of XmlElement.



18
19
20
21
22
23
24
25
26
# File 'lib/edifact_converter/edi2xml11/xml_handler.rb', line 18

def initialize(options)
  self.children = []
  options.each do |attribute, value|
    if ATTRIBUTES.include? attribute.to_sym
      send "#{attribute}=", value
    end
  end
  parent.children << self if parent
end

Instance Method Details

#render(xml) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/edifact_converter/edi2xml11/xml_handler.rb', line 28

def render(xml)
  args = []
  args << text if text
  attributes = {}
  unless EdifactConverter::Configuration.hide_position?
    attributes[:linie] = position.line
    attributes[:position] = position.column
  end
  attributes[:hidden] = true if hidden
  args << attributes
  xml.send(name, *args) do |newxml|
    children.each do |child|
      child.render xml
    end
  end
end