class EDI::E::StreamingBuilder
Class StreamingBuilder
¶ ↑
The StreamingBuilder
parses the input stream just like StreamingParser
and in addition builds the complete interchange.
This method is the new basis of Interchange.parse
. You might want to study its callbacks to get some ideas on how to create a special-purpose parser/builder of your own.
Public Class Methods
new(auto_validate=true)
click to toggle source
# File lib/edi4r/edifact.rb, line 1827 def initialize(auto_validate=true) @ic = nil @curr_group = @curr_msg = nil @una = nil @is_iedi = false @auto_validate = auto_validate end
Public Instance Methods
interchange()
click to toggle source
# File lib/edi4r/edifact.rb, line 1836 def interchange @ic end
on_interchange_end()
click to toggle source
# File lib/edi4r/edifact.rb, line 1894 def on_interchange_end if @auto_validate @ic.header.validate @ic.trailer.validate # Content is already validated through @ic.add() and @curr_group.add() end end
on_segment( s, tag )
click to toggle source
Overwrite this method to react on segments of interest
Note: For a skeleton Builder (just UNB/UNG/UNT etc), overwrite with an empty method.
Calls superclass method
EDI::E::StreamingParser#on_segment
# File lib/edi4r/edifact.rb, line 1888 def on_segment( s, tag ) @curr_msg.add @curr_msg.parse_segment( s ) super end
on_una( s )
click to toggle source
# File lib/edi4r/edifact.rb, line 1841 def on_una( s ) @una = s.dup end
on_unb_uib( s, tag )
click to toggle source
# File lib/edi4r/edifact.rb, line 1845 def on_unb_uib( s, tag ) # Expecting: "UNB+UNOA:3+...", "UIB+UNOC:4..." @ic = Interchange.new( :i_edi => (@is_iedi = tag[1]==?I), :charset => s[4,4], :version => s[9].to_i-?0.to_i, # 1,2,3,4 (int) :una_string => @una ) @ic.header = Segment.parse( @ic, s ) end
on_une( s )
click to toggle source
# File lib/edi4r/edifact.rb, line 1863 def on_une( s ) @curr_group.trailer = Segment.parse( @curr_group, s ) @ic.add( @curr_group, @auto_validate ) end
on_ung( s )
click to toggle source
# File lib/edi4r/edifact.rb, line 1858 def on_ung( s ) @curr_group = @ic.new_msggroup( @ic.parse_segment(s,'UNG') ) @curr_group.header = Segment.parse( @curr_group, s ) end
on_unh_uih( s, tag )
click to toggle source
# File lib/edi4r/edifact.rb, line 1868 def on_unh_uih( s, tag ) # FIXME: @is_edi and tag should correspond! seg = @ic.parse_segment(s,tag) @curr_msg = (@curr_group || @ic).new_message( seg ) # @curr_msg = (@curr_group || @ic).new_message( @ic.parse_segment(s,tag) ) @curr_msg.header = Segment.parse( @curr_msg, s ) end
on_unt_uit( s, tag )
click to toggle source
# File lib/edi4r/edifact.rb, line 1876 def on_unt_uit( s, tag ) # FIXME: @is_edi and tag should correspond! @curr_msg.trailer = Segment.parse( @curr_msg, s ) # puts "on_unt_uit: #@curr_msg" @curr_group.nil? ? @ic.add( @curr_msg, @auto_validate ) : @curr_group.add( @curr_msg ) end
on_unz_uiz( s, tag )
click to toggle source
# File lib/edi4r/edifact.rb, line 1853 def on_unz_uiz( s, tag ) # FIXME: @is_edi and tag should correspond! @ic.trailer = Segment.parse( @ic, s ) end