Class: Eancom::Edifact::Composite
- Inherits:
-
Object
- Object
- Eancom::Edifact::Composite
- Defined in:
- lib/eancom/edifact/composite.rb
Defined Under Namespace
Classes: DataTypeError
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #add(key, value) ⇒ Object
- #delete(key) ⇒ Object
- #get(key) ⇒ Object
-
#initialize ⇒ Composite
constructor
A new instance of Composite.
- #to_array ⇒ Object
Constructor Details
#initialize ⇒ Composite
Returns a new instance of Composite.
8 9 10 |
# File 'lib/eancom/edifact/composite.rb', line 8 def initialize @data = {} end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
6 7 8 |
# File 'lib/eancom/edifact/composite.rb', line 6 def data @data end |
Instance Method Details
#add(key, value) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/eancom/edifact/composite.rb', line 12 def add(key, value) if value.kind_of?(Data) @data[key] = value else raise DataTypeError.new('Added value is not of type Data.') end end |
#delete(key) ⇒ Object
24 25 26 |
# File 'lib/eancom/edifact/composite.rb', line 24 def delete(key) @data.delete(key) end |
#get(key) ⇒ Object
20 21 22 |
# File 'lib/eancom/edifact/composite.rb', line 20 def get(key) @data[key] end |
#to_array ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/eancom/edifact/composite.rb', line 28 def to_array array = [] @data.each do |key, value| array << key end array end |