class EDI::E::CDE
Class EDI::E::CDE
This class implements UN/EDIFACT composite data elements C507 etc., including the service CDEs S001, S009 …
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/edifact.rb, line 1347 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{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/edifact.rb, line 1362 def new_DE(id, status, fmt) DE.new(self, id, status, fmt) end
parse(buf)
click to toggle source
# File lib/edi4r/edifact.rb, line 1367 def parse (buf) # Buffer contains content of a single CDE return nil unless buf obj_list = EDI::E::edi_split( buf, root.una.ce_sep, root.una.esc_char ) each {|obj| obj.parse( obj_list.shift ) } # FIXME: Error handling needed here if obj_list is not exhausted now! end
to_din16557_4( xel, rep=nil )
click to toggle source
# File lib/edi4r/edifact-rexml.rb, line 168 def to_din16557_4( xel, rep=nil ) prefix = name prefix += rep.to_s if rep names.uniq.each do |nm| # Array of all items with this name a = self[nm]; max = a.size raise "DIN16557-4 does not support more than 9 repetitions" if max > 9 raise "Lookup error (should never occur)" if max == 0 if max == 1 obj = a.first obj.to_din16557_4( xel, nil, prefix ) unless obj.empty? else a.each_with_index do |obj, i| obj.to_din16557_4( xel, i+1, prefix ) unless obj.empty? end end end end
to_s()
click to toggle source
# File lib/edi4r/edifact.rb, line 1375 def to_s rt = self.root s = ''; skip_count = 0 ce_sep = rt.una.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