Sha256: 7dafd7db3d8e59849c5defc8e0399ee81ed9ab8e3ff741272e821f4e8904da92

Contents?: true

Size: 1.13 KB

Versions: 3

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module Eancom
  module Edifact
    class Document
      attr_accessor :header_element, :body_element, :footer_element

      def initialize
        @header_element = Header.new
        @body_element = Body.new
        @footer_element = Footer.new
      end

      def header
        yield(@header_element)
      end

      def body
        yield(@body_element)
      end

      def footer
        yield(@footer_element)
      end

      def add_to_header(segment)
        @header_element.segment(segment)
      end

      def add_to_body(segment)
        @body_element.segment(segment)
      end

      def add_to_footer(segment)
        @footer_element.segment(segment)
      end

      def total_segments
        total = 0
        total += @body_element.segments.count
        total
      end

      def to_s(debug: false)
        "#{@header_element.to_s(debug: debug)}#{@body_element.to_s(debug: debug)}#{@footer_element.to_s(debug: debug)}"
      end

      def to_json(_obj = nil)
        {
          **@header_element.to_json_hash,
          **@body_element.to_json_hash
        }.to_json
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
eancom-1.6.3 lib/eancom/edifact/document.rb
eancom-1.6.2 lib/eancom/edifact/document.rb
eancom-1.6.0 lib/eancom/edifact/document.rb