Class: SuperMap::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/super_map.rb

Overview

Map element. Rarely used directly, usually the map object itself is queried for element properties.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(list, key, value, attributes = {}) ⇒ Element

Creates new list element.



45
46
47
48
49
# File 'lib/super_map.rb', line 45

def initialize( list, key, value, attributes = {} )
  raise "Key must be a Symbol" unless key.is_a? Symbol
  raise "Value must NOT be a Symbol" if value.is_a? Symbol
  @list, @key, @value, @attributes = list, key, value, attributes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



59
60
61
# File 'lib/super_map.rb', line 59

def method_missing( name, *args )
  return @attributes[name] || super( name, *args )
end

Instance Attribute Details

#attributesObject (readonly)

Additional information about element, eg. time frame, additional attributes. Also contains the label if not default or provided by I18n. Takes the form of a Hash.



42
43
44
# File 'lib/super_map.rb', line 42

def attributes
  @attributes
end

#keyObject (readonly)

Key (symbol) - used for getting element by symbolic name



35
36
37
# File 'lib/super_map.rb', line 35

def key
  @key
end

#valueObject (readonly)

Value - corresponds to key, usually an integer or string to be stored in database



38
39
40
# File 'lib/super_map.rb', line 38

def value
  @value
end

Instance Method Details

#descriptionObject



55
56
57
# File 'lib/super_map.rb', line 55

def description
  translated_attribute( :description )
end

#labelObject



51
52
53
# File 'lib/super_map.rb', line 51

def label
  translated_attribute( :label )
end

#to_aObject

Returns all initializing arguments as passed to SuperMap constructor - this method is used for cloning to another SuperMap.



65
66
67
# File 'lib/super_map.rb', line 65

def to_a
  [key, value, attributes]
end