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