Sha256: 43a26288248715aaaadd121964d36a7c7bed89f70f82411f7d8135517fc69820

Contents?: true

Size: 654 Bytes

Versions: 3

Compression:

Stored size: 654 Bytes

Contents

module Eancom
  module Edifact
    class Item

      attr_accessor :hash

      def initialize
        @hash = {}
      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
        @hash
      end

      def empty?
        @hash.empty?
      end

      private

      def group_name(segment)
        if segment.item_group_name
          segment.item_group_name
        else
          segment.group_name
        end
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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