Class: CfScript::AttributeList

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/cf_script/object/attribute_list.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes = []) ⇒ AttributeList

Returns a new instance of AttributeList.



7
8
9
10
11
12
13
# File 'lib/cf_script/object/attribute_list.rb', line 7

def initialize(attributes = [])
  @list = {}

  attributes.each do |attribute|
    self << attribute
  end
end

Instance Method Details

#<<(attr) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/cf_script/object/attribute_list.rb', line 23

def <<(attr)
  if @list.key?(attr.name)
    raise "Duplicate attribute '#{attr.name}'"
  end

  @list[attr.name] = attr
end

#namesObject



15
16
17
# File 'lib/cf_script/object/attribute_list.rb', line 15

def names
  @list.keys
end

#to_hObject



31
32
33
34
35
36
37
38
39
# File 'lib/cf_script/object/attribute_list.rb', line 31

def to_h
  hash = {}

  @list.each do |name, attr|
    hash[name] = attr.value
  end

  hash
end

#valuesObject



19
20
21
# File 'lib/cf_script/object/attribute_list.rb', line 19

def values
  @list.values.map { |attr| attr.value }
end