class EDI::Collection_S

A “segment-like” collection, base class of Segment and CDE

Utility: Separator method for UN/EDIFACT segments/CDEs

Attributes

maxrep[RW]
rep[RW]
status[RW]

Public Class Methods

new(parent, name, status=nil) click to toggle source
Calls superclass method EDI::Collection::new
# File lib/edi4r.rb, line 435
def initialize(parent, name, status=nil)
  @status = status
  super( parent, parent.root, name)
end

Public Instance Methods

empty?() click to toggle source

Returns true if all contained elements are empty.

# File lib/edi4r.rb, line 471
def empty?
  empty = true
  each {|obj| empty &= obj.empty? } # DE or CDE
  empty
end
inspect( indent='', symlist=[] ) click to toggle source
Calls superclass method EDI::Collection#inspect
# File lib/edi4r.rb, line 486
def inspect( indent='', symlist=[] )
  symlist += [:status, :rep, :maxrep]
  super
end
required?() click to toggle source

Returns true if this segment or CDE is mandatory / required according to its defining “Diagram”.

# File lib/edi4r.rb, line 481
def required?
  @status == 'M' or @status == 'R'
end
to_xml( xel_parent, instance=1 ) click to toggle source
# File lib/edi4r/rexml.rb, line 42
def to_xml( xel_parent, instance=1 )
  xel  = REXML::Element.new( normalized_class_name ) 
  xel.attributes["name"]  = @name
  xel.attributes["instance"]  = instance.to_s 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
validate( err_count=0 ) click to toggle source
# File lib/edi4r.rb, line 441
def validate( err_count=0 )
  location = "#{parent.name} - #{@name}"
  if empty?
    if required?
      EDI::logger.warn "#{location}: Empty though mandatory!"
      err_count += 1
    end
  else
    if rep && maxrep && rep > maxrep
      EDI::logger.warn "#{location}: Too often repeated: #{rep} > #{maxrep}!"
      err_count += 1
    end
    each {|obj| err_count += obj.validate}
  end
  err_count
end