Sha256: c7d9245e78529cfcf5c9a1d7c262854288ce01da1591abf2212c311138196ab8

Contents?: true

Size: 656 Bytes

Versions: 13

Compression:

Stored size: 656 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

13 entries across 13 versions & 1 rubygems

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