class EDI::S::Interchange

Attributes

basedata[R]
charset[RW]
output_mode[RW]

Public Class Methods

new( user_par={} ) click to toggle source
Calls superclass method EDI::Interchange::new
# File lib/edi4r/sedas.rb, line 113
def initialize( user_par={} )
  super( user_par ) # just in case...
  par = {:syntax  => 'S',
         :output_mode => nil,
         :charset => 'ISO-8859-15', # not used yet...
  }.update( user_par )

  @syntax = par[:syntax]   # UN/EDIFACT
  @output_mode = par[:output_mode]
  @charset = par[:charset]

  # Temporary - adjust to current SEDAS needs:
  @illegal_charset_pattern = /[^-A-Za-z0-9 .,()\/=!%"&*;<>'+:?\xa0-\xff]+/

  check_consistencies
  init_ndb
end
parse( hnd=$stdin, auto_validate=true ) click to toggle source

Reads SEDAS data from given stream (default: $stdin), parses it and returns an Interchange object

# File lib/edi4r/sedas.rb, line 136
def Interchange.parse( hnd=$stdin, auto_validate=true )
  builder = StreamingBuilder.new( auto_validate )
  builder.go( hnd )
  builder.interchange
end
parse_xml(xdoc) click to toggle source
# File lib/edi4r/sedas.rb, line 169
def Interchange.parse_xml(xdoc)
  ic = Interchange.new # ({:sap_type => xdoc.root.attributes['version']})
  xdoc.root.elements.each('Message') do |xel|
    ic.add( Message.parse_xml( ic, xel ) )
  end
  ic
end
peek(hnd=$stdin, params={}) click to toggle source

Read maxlen bytes from $stdin (default) or from given stream (SEDAS data expected), and peek into first segment (00).

Returns an empty Interchange object with a properly header filled.

Intended use:

Efficient routing by reading just 00 data: sender/recipient/ref/test
# File lib/edi4r/sedas.rb, line 151
def Interchange.peek(hnd=$stdin, params={}) # Handle to input stream
  builder = StreamingBuilder.new( false )
  if params[:deep_peek]
    def builder.on_segment( s, tag )
    end
  else
    def builder.on_01( s )
      throw :done
    end
    def builder.on_msg_start( s, tag )
      throw :done  # FIXME: UNZ??
    end
  end
  builder.go( hnd )
  builder.interchange
end

Public Instance Methods

check_consistencies() click to toggle source

Currently, this is almost a dummy method It might grow into something useful. Keep it to stay consistent with other module add-ons.

# File lib/edi4r/sedas.rb, line 97
def check_consistencies
  if 'S' != @syntax
    raise "#{@syntax} - syntax must be 'S' (SEDAS)!"
  end

  case @charset
  when 'ISO-8859-15'
    # ok
    #   when '...'
  else
    raise "#{@charset} - character set not supported!"
  end
  # Add more rules ...
end
init_ndb() click to toggle source
# File lib/edi4r/sedas.rb, line 89
def init_ndb
  @basedata = EDI::Dir::Directory.create( root.syntax )
end
new_message(params) click to toggle source
# File lib/edi4r/sedas.rb, line 182
def new_message(params)
  Message.new(self, params)
end
new_msggroup(params) click to toggle source
# File lib/edi4r/sedas.rb, line 178
def new_msggroup(params)
  MsgGroup.new(self, params)
end
new_segment(tag) click to toggle source
# File lib/edi4r/sedas.rb, line 186
def new_segment(tag)
  Segment.new(self, tag)
end
parse_message(list) click to toggle source
# File lib/edi4r/sedas.rb, line 191
def parse_message(list)
  Message.parse(self, list)
end
parse_segment(buf) click to toggle source
# File lib/edi4r/sedas.rb, line 195
def parse_segment(buf)
  Segment.parse(self, buf)
end