class EDI::A::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/ansi_x12.rb, line 1589
def initialize(auto_validate=true)
  @ic = nil
  @curr_group = @curr_msg = nil
  @auto_validate = auto_validate
end

Public Instance Methods

interchange() click to toggle source
# File lib/edi4r/ansi_x12.rb, line 1596
def interchange
  @ic
end
on_ge( s ) click to toggle source
# File lib/edi4r/ansi_x12.rb, line 1619
def on_ge( s )
  @curr_group.trailer = Segment.parse( @curr_group, s )
  @ic.add( @curr_group, @auto_validate )
end
on_gs( s ) click to toggle source
# File lib/edi4r/ansi_x12.rb, line 1614
def on_gs( s )
  @curr_group = @ic.new_msggroup( @ic.parse_segment(s,'GS') )
  @curr_group.header = Segment.parse( @curr_group, s )
end
on_iea( s, tag ) click to toggle source
# File lib/edi4r/ansi_x12.rb, line 1610
def on_iea( s, tag )
  @ic.trailer = Segment.parse( @ic, s )
end
on_interchange_end() click to toggle source
# File lib/edi4r/ansi_x12.rb, line 1648
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_isa( s, tag, seps ) click to toggle source
# File lib/edi4r/ansi_x12.rb, line 1601
def on_isa( s, tag, seps ) # Expecting: "ISA*...~"
  params = { :version => s[84,5] } # '00401', '00500',
  [:ce_sep, :de_sep, :rep_sep, :seg_term].each_with_index do |sep, i|
    params[sep] = seps[i]
  end
  @ic = Interchange.new( params )
  @ic.header = Segment.parse( @ic, s )
end
on_se( s, tag ) click to toggle source
# File lib/edi4r/ansi_x12.rb, line 1631
def on_se( s, tag )
  @curr_msg.trailer = Segment.parse( @curr_msg, s )
  #      puts "on_unt_uit: #@curr_msg"
  @curr_group.add( @curr_msg )
end
on_segment( s, tag ) click to toggle source

Overwrite this method to react on segments of interest

Note: For a skeleton Builder (just ISA/GS/ST etc), overwrite with an empty method.

Calls superclass method EDI::A::StreamingParser#on_segment
# File lib/edi4r/ansi_x12.rb, line 1642
def on_segment( s, tag )
  @curr_msg.add @curr_msg.parse_segment( s )
  super
end
on_st( s, tag ) click to toggle source
# File lib/edi4r/ansi_x12.rb, line 1624
    def on_st( s, tag )
      seg = @ic.parse_segment(s,tag)
      @curr_msg = @curr_group.new_message( seg )
#      @curr_msg = (@curr_group || @ic).new_message( @ic.parse_segment(s,tag) )
      @curr_msg.header = Segment.parse( @curr_msg, s )
    end