Class: Eancom::Edifact::Location
- Inherits:
-
Object
- Object
- Eancom::Edifact::Location
- Defined in:
- lib/eancom/edifact/location.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
- #empty? ⇒ Boolean
-
#initialize ⇒ Location
constructor
A new instance of Location.
- #start_item ⇒ Object
- #to_json_hash ⇒ Object
Constructor Details
#initialize ⇒ Location
Returns a new instance of Location.
8 9 10 11 |
# File 'lib/eancom/edifact/location.rb', line 8 def initialize @items = [] @hash = {} end |
Instance Attribute Details
#hash ⇒ Object
Returns the value of attribute hash.
6 7 8 |
# File 'lib/eancom/edifact/location.rb', line 6 def hash @hash end |
#items ⇒ Object
Returns the value of attribute items.
6 7 8 |
# File 'lib/eancom/edifact/location.rb', line 6 def items @items end |
Instance Method Details
#<<(segment) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/eancom/edifact/location.rb', line 17 def <<(segment) start_item if segment.starts_item? if @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
13 14 15 |
# File 'lib/eancom/edifact/location.rb', line 13 def add_item(item) @items << item end |
#empty? ⇒ Boolean
38 39 40 |
# File 'lib/eancom/edifact/location.rb', line 38 def empty? @hash.empty? end |
#start_item ⇒ Object
42 43 44 45 46 47 |
# File 'lib/eancom/edifact/location.rb', line 42 def start_item if @item && !@item.empty? add_item(@item.to_json_hash) end @item = Eancom::Edifact::Item.new end |
#to_json_hash ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/eancom/edifact/location.rb', line 30 def to_json_hash if @item && !@item.empty? add_item(@item.to_json_hash) end @hash.merge({ items: @items }) end |