class EDI::S::Segment
Public Class Methods
new(p, tag)
click to toggle source
Calls superclass method
EDI::Collection_S::new
# File lib/edi4r/sedas.rb, line 349 def initialize(p, tag) super( p, tag ) segment_list = root.basedata.segment(tag) raise "Segment \'#{tag}\' not found" if segment_list.nil? # each_BCDS_Entry('s'+tag) do |entry| # This does not work here... segment_list.each do |entry| id = entry.name status = entry.status # puts "Seeking DE >>#{tag+':'+id}<<" # Regular lookup fmt = fmt_of_DE(tag+':'+id) add new_DE(id, status, fmt) end end
parse(p, buf, tag_expected=nil)
click to toggle source
Buffer contains a single segment (line)
# File lib/edi4r/sedas.rb, line 373 def Segment.parse (p, buf, tag_expected=nil) case tag = buf[0,2] when '00', '01', '03', '51', '96', '98','99' # take just the rec_id as tag else # append "Folgesatz" id tag +=buf[146,2] end seg = p.new_segment(tag) if tag_expected and tag_expected != tag raise "Wrong segment name! Expected: #{tag_expected}, found: #{tag}" end seg.each {|obj| obj.parse(buf) } seg end
Public Instance Methods
new_DE(id, status, fmt)
click to toggle source
# File lib/edi4r/sedas.rb, line 367 def new_DE(id, status, fmt) DE.new(self, id, status, fmt) end
to_s()
click to toggle source
# File lib/edi4r/sedas.rb, line 392 def to_s line = '' crlf = "\x0d\x0a" return line if empty? if root.output_mode == :linebreak each do |obj| next if obj.empty? line << name.ljust(12)+obj.name.ljust(12)+'['+obj.to_s+']' unless obj.empty? end else last_nonempty_de = nil each {|obj| last_nonempty_de = obj unless obj.empty? } each {|obj| line += obj.to_s; break if obj.object_id == last_nonempty_de.object_id } end line << crlf line end
Private Instance Methods
method_missing(sym, *par)
click to toggle source
SEDAS field names direcly qualify as Ruby method names, and there are neither composites nor arrays, so we can simplify access to fields here.
Calls superclass method
EDI::Collection#method_missing
# File lib/edi4r/sedas.rb, line 417 def method_missing(sym, *par) if sym.id2name =~ /^(\w+)(=)?/ rc = lookup($1) if rc.is_a? Array if rc.size==1 rc = rc.first elsif rc.size==0 return super end end if $2 # Setter raise TypeError, "Can't assign to a #{rc.class} object '#$1'" unless rc.is_a? DE rc.value = par[0] else # Getter return rc.value if rc.is_a? DE err_msg = "No DE with name '#$1' found, instead there is a '#{rc.class}'!" raise TypeError, err_msg end else super end end