Sha256: 75eac2b90b3674dbd02a21c53e51c0aea37fee99b00e55427380787488c44944

Contents?: true

Size: 857 Bytes

Versions: 1

Compression:

Stored size: 857 Bytes

Contents

# frozen_string_literal: true

module Eancom
  module Edifact
    class Body < DocumentElement
      attr_accessor :hash, :messages, :locations, :items

      def initialize
        super
        @hash = {}
        @messages = []
      end

      def to_json_hash
        @to_json_hash ||= build_json_hash
      end

      def start_message
        if @message
          @messages << @message.to_json_hash
        end
        @message = Eancom::Edifact::Message.new
      end

      private

      def group_name(segment)
        segment.group_name
      end

      def build_json_hash
        @segments.each do |segment|
          start_message if segment.starts_message?
          @message << segment
        end
        messages << @message.to_json_hash

        {
          body: hash.merge({ messages: messages })
        }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
eancom-1.6.0 lib/eancom/edifact/body.rb