Class: Eancom::Edifact::Body
- Inherits:
-
DocumentElement
- Object
- DocumentElement
- Eancom::Edifact::Body
- Defined in:
- lib/eancom/edifact/body.rb
Instance Attribute Summary collapse
-
#hash ⇒ Object
Returns the value of attribute hash.
-
#items ⇒ Object
Returns the value of attribute items.
-
#messages ⇒ Object
Returns the value of attribute messages.
Attributes inherited from DocumentElement
Instance Method Summary collapse
-
#initialize ⇒ Body
constructor
A new instance of Body.
- #start_item(segment) ⇒ Object
- #start_message(segment) ⇒ Object
- #to_json_hash ⇒ Object
Methods inherited from DocumentElement
Constructor Details
#initialize ⇒ Body
Returns a new instance of Body.
7 8 9 10 11 |
# File 'lib/eancom/edifact/body.rb', line 7 def initialize super @hash = {} @messages = [] end |
Instance Attribute Details
#hash ⇒ Object
Returns the value of attribute hash.
5 6 7 |
# File 'lib/eancom/edifact/body.rb', line 5 def hash @hash end |
#items ⇒ Object
Returns the value of attribute items.
5 6 7 |
# File 'lib/eancom/edifact/body.rb', line 5 def items @items end |
#messages ⇒ Object
Returns the value of attribute messages.
5 6 7 |
# File 'lib/eancom/edifact/body.rb', line 5 def @messages end |
Instance Method Details
#start_item(segment) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/eancom/edifact/body.rb', line 40 def start_item(segment) if @item && !@item.empty? @message.add_item(@item.to_json_hash) end @item = Eancom::Edifact::Item.new() end |
#start_message(segment) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/eancom/edifact/body.rb', line 29 def (segment) if @message @messages << @message.to_json_hash if @item && !@item.empty? @message.add_item(@item.to_json_hash) end @item = nil end @message = Eancom::Edifact::Message.new() end |
#to_json_hash ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/eancom/edifact/body.rb', line 13 def to_json_hash @segments.each do |segment| (segment) if segment. start_item(segment) if segment.starts_item? if @item @item << segment else @message << segment end end @message.add_item(@item.to_json_hash) @messages << @message.to_json_hash hash.merge!({ messages: }) { body: hash } end |