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.



47
48
49
50
51
# File 'lib/super_map.rb', line 47

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



61
62
63
# File 'lib/super_map.rb', line 61

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.



44
45
46
# File 'lib/super_map.rb', line 44

def attributes
  @attributes
end

#keyObject (readonly)

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



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

def key
  @key
end

#valueObject (readonly)

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



40
41
42
# File 'lib/super_map.rb', line 40

def value
  @value
end

Instance Method Details

#descriptionObject



57
58
59
# File 'lib/super_map.rb', line 57

def description
  translated_attribute( :description )
end

#labelObject



53
54
55
# File 'lib/super_map.rb', line 53

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.



67
68
69
# File 'lib/super_map.rb', line 67

def to_a
  [key, value, attributes]
end