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.
-
#locations ⇒ Object
Returns the value of attribute locations.
Instance Method Summary collapse
- #<<(segment) ⇒ Object
- #add_item(item) ⇒ Object
- #add_location(location) ⇒ Object
-
#initialize ⇒ Message
constructor
A new instance of Message.
- #to_json_hash ⇒ Object
Constructor Details
#initialize ⇒ Message
Returns a new instance of Message.
8 9 10 11 12 |
# File 'lib/eancom/edifact/message.rb', line 8 def initialize @locations = [] @items = [] @hash = {} end |
Instance Attribute Details
#hash ⇒ Object
Returns the value of attribute hash.
6 7 8 |
# File 'lib/eancom/edifact/message.rb', line 6 def hash @hash end |
#items ⇒ Object
Returns the value of attribute items.
6 7 8 |
# File 'lib/eancom/edifact/message.rb', line 6 def items @items end |
#locations ⇒ Object
Returns the value of attribute locations.
6 7 8 |
# File 'lib/eancom/edifact/message.rb', line 6 def locations @locations end |
Instance Method Details
#<<(segment) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/eancom/edifact/message.rb', line 22 def <<(segment) start_location if segment.starts_location? start_item if segment.starts_item? if @location @location << segment elsif @item @item << segment elsif 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
18 19 20 |
# File 'lib/eancom/edifact/message.rb', line 18 def add_item(item) @items << item end |
#add_location(location) ⇒ Object
14 15 16 |
# File 'lib/eancom/edifact/message.rb', line 14 def add_location(location) @locations << location end |
#to_json_hash ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/eancom/edifact/message.rb', line 38 def to_json_hash if @location && !@location.empty? add_location(@location.to_json_hash) end if @item && !@item.empty? add_item(@item.to_json_hash) end = {} .merge!(@hash) .merge!({ locations: @locations }) if !@locations.empty? .merge!({ items: @items }) if !@items.empty? end |