Class: Eancom::Parser::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/eancom/parser/document.rb

Defined Under Namespace

Classes: SegmentTypeNotDefined

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file:) ⇒ Document

Returns a new instance of Document.


10
11
12
13
# File 'lib/eancom/parser/document.rb', line 10

def initialize(file:)
  @file = file
  @document = Eancom::Edifact::Document.new
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.


8
9
10
# File 'lib/eancom/parser/document.rb', line 8

def document
  @document
end

#fileObject (readonly)

Returns the value of attribute file.


8
9
10
# File 'lib/eancom/parser/document.rb', line 8

def file
  @file
end

Instance Method Details

#parse(header_only: false) ⇒ Object


15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/eancom/parser/document.rb', line 15

def parse(header_only: false)
  content.split(segment_delimiter).each do |segment_string|
    segment = Parser::Segment.new(segment_string)

    if header_only && segment.segment_class::TYPE != :header
      next
    end

    segment = segment.parse
    add(segment)
  end
  @document
end