Sha256: 1d67abf252e383249fc873ad17ede728615d52d8541b54410f5a17e540745ded

Contents?: true

Size: 1.22 KB

Versions: 12

Compression:

Stored size: 1.22 KB

Contents

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(&block)
        yield(@header_element)
      end

      def body(&block)
        yield(@body_element)
      end

      def footer(&block)
        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)
        stream = ''
        stream << @header_element.to_s(debug: debug)
        stream << @body_element.to_s(debug: debug)
        stream << @footer_element.to_s(debug: debug)
        stream
      end

      def to_json
        hash = {}
        hash.merge! @header_element.to_json_hash
        hash.merge! @body_element.to_json_hash
        hash.to_json
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
eancom-1.5.7 lib/eancom/edifact/document.rb
eancom-1.5.6 lib/eancom/edifact/document.rb
eancom-1.5.5 lib/eancom/edifact/document.rb
eancom-1.5.4 lib/eancom/edifact/document.rb
eancom-1.5.2 lib/eancom/edifact/document.rb
eancom-1.5.1 lib/eancom/edifact/document.rb
eancom-1.5.0 lib/eancom/edifact/document.rb
eancom-1.4.0 lib/eancom/edifact/document.rb
eancom-1.3.0 lib/eancom/edifact/document.rb
eancom-1.2.0 lib/eancom/edifact/document.rb
eancom-1.1.1 lib/eancom/edifact/document.rb
eancom-1.1.0 lib/eancom/edifact/document.rb