Class: Eancom::Edifact::Composite

Inherits:
Object
  • Object
show all
Defined in:
lib/eancom/edifact/composite.rb

Defined Under Namespace

Classes: DataTypeError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeComposite

Returns a new instance of Composite.



8
9
10
# File 'lib/eancom/edifact/composite.rb', line 8

def initialize
  @data = {}
end

Instance Attribute Details

#dataObject (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_arrayObject



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