Class: Edifunct::Parser

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

Overview

The main entry point to converting a raw EDIFACT message into a structured object. The structure is dictated by the provided schema.

Instance Method Summary collapse

Constructor Details

#initialize(message, schema:, tokenizer: nil) ⇒ Parser

Returns a new instance of Parser.



10
11
12
13
14
# File 'lib/edifunct/parser.rb', line 10

def initialize(message, schema:, tokenizer: nil)
  @message = message
  @schema = schema
  @tokenizer = tokenizer || Tokenizer.for_message(message)
end

Instance Method Details

#as_root_group(root_group_tag = "<root>") ⇒ Object



16
17
18
19
20
21
22
# File 'lib/edifunct/parser.rb', line 16

def as_root_group(root_group_tag = "<root>")
  @segments = @tokenizer.as_segments(@message)

  SegmentGroup.new(root_group_tag).tap do |root_group|
    parse_group(root_group, schema)
  end
end