Class: Eancom::Edifact::Message
- Inherits:
-
Object
- Object
- Eancom::Edifact::Message
- Defined in:
- lib/eancom/edifact/message.rb
Instance Attribute Summary collapse
-
#hash ⇒ Object
Returns the value of attribute hash.
-
#items ⇒ Object
Returns the value of attribute items.
Instance Method Summary collapse
- #<<(segment) ⇒ Object
- #add_item(item) ⇒ Object
-
#initialize ⇒ Message
constructor
A new instance of Message.
- #to_json_hash ⇒ Object
Constructor Details
#initialize ⇒ Message
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
#hash ⇒ Object
Returns the value of attribute hash.
5 6 7 |
# File 'lib/eancom/edifact/message.rb', line 5 def hash @hash end |
#items ⇒ Object
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_hash ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/eancom/edifact/message.rb', line 25 def to_json_hash = {} items_hash = { items: @items } .merge!(@hash) .merge!(items_hash) end |