Class: EDI::Collection_S

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

Overview

Utility: Separator method for UN/EDIFACT segments/CDEs

Instance Method Summary collapse

Instance Method Details

#to_xml(xel_parent, instance = 1) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/edi4r/rexml.rb', line 38

def to_xml( xel_parent, instance=1 )
  xel  = REXML::Element.new( normalized_class_name ) 
  xel.attributes["name"]  = @name
  xel.attributes["instance"]  = instance if instance > 1
  xel_parent.elements << xel
  instance_counter = Hash.new(0)
  each do |obj| 
    i = (instance_counter[obj.name] += 1)
    obj.to_xml( xel, i ) unless obj.empty?
  end
  xel
end