lib/eancom/edifact/document.rb in eancom-1.5.7 vs lib/eancom/edifact/document.rb in eancom-1.6.0
- old
+ new
@@ -1,27 +1,27 @@
+# frozen_string_literal: true
+
module Eancom
module Edifact
class Document
+ attr_accessor :header_element, :body_element, :footer_element
- attr_accessor :header_element,
- :body_element, :footer_element
-
def initialize
- @header_element = Header.new()
- @body_element = Body.new()
- @footer_element = Footer.new()
+ @header_element = Header.new
+ @body_element = Body.new
+ @footer_element = Footer.new
end
- def header(&block)
+ def header
yield(@header_element)
end
- def body(&block)
+ def body
yield(@body_element)
end
- def footer(&block)
+ def footer
yield(@footer_element)
end
def add_to_header(segment)
@header_element.segment(segment)
@@ -40,21 +40,17 @@
total += @body_element.segments.count
total
end
def to_s(debug: false)
- stream = ''
- stream << @header_element.to_s(debug: debug)
- stream << @body_element.to_s(debug: debug)
- stream << @footer_element.to_s(debug: debug)
- stream
+ "#{@header_element.to_s(debug: debug)}#{@body_element.to_s(debug: debug)}#{@footer_element.to_s(debug: debug)}"
end
- def to_json
- hash = {}
- hash.merge! @header_element.to_json_hash
- hash.merge! @body_element.to_json_hash
- hash.to_json
+ def to_json(_obj = nil)
+ {
+ **@header_element.to_json_hash,
+ **@body_element.to_json_hash
+ }.to_json
end
end
end
end