lib/eancom/parser/document.rb in eancom-1.6.3 vs lib/eancom/parser/document.rb in eancom-2.0.0
- old
+ new
@@ -1,7 +1,5 @@
-# frozen_string_literal: true
-
module Eancom
module Parser
class Document
class SegmentTypeNotDefined < StandardError; end
@@ -10,18 +8,13 @@
def initialize(file:)
@file = file
@document = Eancom::Edifact::Document.new
end
- def parse(header_only: false)
+ def parse
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
@@ -32,11 +25,11 @@
if segment.is_header?
@document.add_to_header(segment)
elsif segment.is_body?
@document.add_to_body(segment)
elsif segment.is_footer?
- @document.add_to_footer(segment)
+ @document.add_to_body(segment)
else
raise SegmentTypeNotDefined
end
end
@@ -58,16 +51,10 @@
def segment_delimiter
DELIMITERS[:segment]
end
def convert(string)
- string.encode(
- 'UTF-8',
- 'binary',
- invalid: :replace,
- undef: :replace,
- replace: ''
- )
+ string.encode('UTF-8')
end
end
end
end