class EDI::A::CDE

Class EDI::A::CDE

This class implements ANSI X12 composite data elements C001 etc.

For internal use only.

Public Class Methods

new(p, name, status) click to toggle source
Calls superclass method EDI::Collection_S::new
# File lib/edi4r/ansi_x12.rb, line 990
def initialize(p, name, status)
  super(p, name, status)

  each_BCDS(name) do |entry|
    id = entry.name
    status = entry.status
    # FIXME: Code redundancy in type detection - remove later!
    if id =~ /\d{1,4}/
      add new_DE(id, status, fmt_of_DE(id))
    else                            # Should never occur
      raise "Not a legal DE: #{id}"
    end
  end
end

Public Instance Methods

new_DE(id, status, fmt) click to toggle source
# File lib/edi4r/ansi_x12.rb, line 1005
def new_DE(id, status, fmt)
  DE.new(self, id, status, fmt)
end
parse(buf) click to toggle source
# File lib/edi4r/ansi_x12.rb, line 1010
def parse (buf)     # Buffer contains content of a single CDE
  return nil unless buf
  obj_list = buf.split( root.re_ce_sep )
  each {|obj| obj.parse( obj_list.shift ) }
  # FIXME: Error handling needed here if obj_list is not exhausted now!
end
to_s() click to toggle source
# File lib/edi4r/ansi_x12.rb, line 1018
def to_s
  rt = self.root
  s = ''; skip_count = 0
  ce_sep = rt.ce_sep.chr
  each {|de| 
    if de.empty?
      skip_count += 1
    else
      if skip_count > 0
        s << ce_sep * skip_count
        skip_count = 0
      end
      s << de.to_s
      skip_count += 1
    end
  }
  s
end