Class: SuperMap::Element
- Inherits:
-
Object
- Object
- SuperMap::Element
- 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
-
#attributes ⇒ Object
readonly
Additional information about element, eg.
-
#key ⇒ Object
readonly
Key (symbol) - used for getting element by symbolic name.
-
#value ⇒ Object
readonly
Value - corresponds to key, usually an integer or string to be stored in database.
Instance Method Summary collapse
- #description ⇒ Object
-
#initialize(list, key, value, attributes = {}) ⇒ Element
constructor
Creates new list element.
- #label ⇒ Object
- #method_missing(name, *args) ⇒ Object
-
#to_a ⇒ Object
Returns all initializing arguments as passed to SuperMap constructor - this method is used for cloning to another SuperMap.
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
#attributes ⇒ Object (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 |
#key ⇒ Object (readonly)
Key (symbol) - used for getting element by symbolic name
35 36 37 |
# File 'lib/super_map.rb', line 35 def key @key end |
#value ⇒ Object (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
#description ⇒ Object
55 56 57 |
# File 'lib/super_map.rb', line 55 def description translated_attribute( :description ) end |
#label ⇒ Object
51 52 53 |
# File 'lib/super_map.rb', line 51 def label translated_attribute( :label ) end |
#to_a ⇒ Object
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 |