Sha256: 79bc5fc1fa72d1f1b2c7df5231bb599187a26a91ecd1e7835e3dce8293396b93

Contents?: true

Size: 748 Bytes

Versions: 13

Compression:

Stored size: 748 Bytes

Contents

module Eancom
  module Edifact
    class Message

      attr_accessor :items, :hash

      def initialize()
        @items = []
        @hash = {}
      end

      def add_item(item)
        @items << item
      end

      def << (segment)
        if name = group_name(segment)
          @hash[name] = [] if @hash[name].nil?
          @hash[name] << segment.to_json_hash
        else
          @hash.merge!(segment.to_json_hash)
        end
      end

      def to_json_hash
        message_hash = {}
        items_hash = { items: @items }
        message_hash.merge!(@hash)
        message_hash.merge!(items_hash)
        message_hash
      end

      private

      def group_name(segment)
        segment.group_name
      end

    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

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