Class: EdifactConverter::EDI2XML11::EdiReader

Inherits:
Object
  • Object
show all
Defined in:
lib/edifact_converter/edi2xml11/edi_reader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(handler = Pipeline.handler) ⇒ EdiReader

Returns a new instance of EdiReader.



8
9
10
11
12
# File 'lib/edifact_converter/edi2xml11/edi_reader.rb', line 8

def initialize(handler = Pipeline.handler)
  self.locator = Locator.new
  self.handler = handler
  handler.locator = locator
end

Instance Attribute Details

#edifileObject

Returns the value of attribute edifile.



6
7
8
# File 'lib/edifact_converter/edi2xml11/edi_reader.rb', line 6

def edifile
  @edifile
end

#handlerObject

Returns the value of attribute handler.



6
7
8
# File 'lib/edifact_converter/edi2xml11/edi_reader.rb', line 6

def handler
  @handler
end

#locatorObject

Returns the value of attribute locator.



6
7
8
# File 'lib/edifact_converter/edi2xml11/edi_reader.rb', line 6

def locator
  @locator
end

Instance Method Details

#parse(edifile, properties, close = false) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/edifact_converter/edi2xml11/edi_reader.rb', line 18

def parse(edifile, properties, close = false)
  locator.properties = properties
  if edifile.kind_of? String
    close = true
    self.edifile = PositionIO.new (File.open edifile, 'rb', encoding: 'ISO-8859-1')
  else
    self.edifile = PositionIO.new edifile
  end
  handler.startDocument
  begin
    eatCrap
    parseUNA
    eatCrap
    while(parseSegment)
      eatCrap
    end
  rescue EOFError
    handler.endDocument
  end
  self.edifile.close if close
  handler.xml
end

#parse_string(edistring, properties) ⇒ Object



14
15
16
# File 'lib/edifact_converter/edi2xml11/edi_reader.rb', line 14

def parse_string(edistring, properties)
  parse StringIO.new(edistring), properties
end