Class: Eancom::Edifact::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/eancom/edifact/message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMessage

Returns a new instance of Message.



7
8
9
10
# File 'lib/eancom/edifact/message.rb', line 7

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

Instance Attribute Details

#hashObject

Returns the value of attribute hash.



5
6
7
# File 'lib/eancom/edifact/message.rb', line 5

def hash
  @hash
end

#itemsObject

Returns the value of attribute items.



5
6
7
# File 'lib/eancom/edifact/message.rb', line 5

def items
  @items
end

Instance Method Details

#<<(segment) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/eancom/edifact/message.rb', line 16

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

#add_item(item) ⇒ Object



12
13
14
# File 'lib/eancom/edifact/message.rb', line 12

def add_item(item)
  @items << item
end

#to_json_hashObject



25
26
27
28
29
30
31
# File 'lib/eancom/edifact/message.rb', line 25

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