class EDI::Collection_HT

A collection with header and trailer, common to Interchange, MsgGroup, and Message. Typically, header and trailer are Segment instances.

Attributes

header[RW]
trailer[RW]

Public Instance Methods

empty?() click to toggle source

Experimental: Ignore content of header / trailer, regard object as empty when nothing “add”ed to it.

# File lib/edi4r.rb, line 404
def empty?
  @a.empty?
end
root=(rt) click to toggle source
Calls superclass method EDI::Collection#root=
# File lib/edi4r.rb, line 394
def root= (rt)
  super( rt )
  @header.root = rt if @header
  @trailer.root = rt if @trailer
end
to_din16557_4( xparent ) click to toggle source

NOTE: Makes sense only in the UN/EDIFACT context, so we list this method here.

# File lib/edi4r/edifact-rexml.rb, line 215
def to_din16557_4( xparent )
  header.to_din16557_4( xparent )
  each {|obj| obj.to_din16557_4( xparent )}
  trailer.to_din16557_4( xparent )
end
to_s( postfix='' ) click to toggle source
# File lib/edi4r.rb, line 417
def to_s( postfix='' )
  s = @header ? @header.to_s + postfix : ''
  each {|obj| s << (obj.is_a?(Segment) ? obj.to_s+postfix : obj.to_s)}
  s << @trailer.to_s+postfix if @trailer
  s
end
to_xml( xel_parent ) click to toggle source
# File lib/edi4r/rexml.rb, line 59
def to_xml( xel_parent )
  xel  = REXML::Element.new( normalized_class_name ) 
  xel.attributes["name"]  = @name
  xel_parent.elements << xel

  xhd = to_xml_header( xel )
  each { |obj| obj.to_xml( xel ) }
  xtr = to_xml_trailer( xel )
  [xel, xhd, xtr] # You might want to add something ...
end
to_xml_header( xparent ) click to toggle source
# File lib/edi4r/rexml.rb, line 71
def to_xml_header( xparent )
  if @header
    xparent << (xel = REXML::Element.new( 'Header' ))
    @header.to_xml( xel )
    return xel
  end
  nil
end
to_xml_trailer( xparent ) click to toggle source
# File lib/edi4r/rexml.rb, line 80
def to_xml_trailer( xparent )
  if @trailer
    xparent << (xel = REXML::Element.new( 'Trailer' ))
    @trailer.to_xml( xel )
    return xel
  end
  nil
end
validate( err_count=0 ) click to toggle source
# File lib/edi4r.rb, line 409
def validate( err_count=0 )
  err_count += @header.validate if @header
  err_count += @trailer.validate if @trailer
  each {|obj| err_count += obj.validate}
  err_count
end