Class: Stockboy::AttributeMap
- Inherits:
-
Object
- Object
- Stockboy::AttributeMap
- Includes:
- Enumerable
- Defined in:
- lib/stockboy/attribute_map.rb
Overview
Table of attributes for finding corresponding field/attribute translations
Instance Method Summary collapse
-
#[](key) ⇒ Attribute
Retrieve an attribute by symbolic name.
-
#attribute_from(key) ⇒ Attribute
Fetch the attribute corresponding to the source field name.
-
#each(*args) {|| ... } ⇒ Enumerator
Enumerate over attributes.
-
#initialize(rows = {}, &block) ⇒ AttributeMap
constructor
Initialize a new attribute map.
Constructor Details
#initialize(rows = {}, &block) ⇒ AttributeMap
Initialize a new attribute map
37 38 39 40 41 42 43 44 |
# File 'lib/stockboy/attribute_map.rb', line 37 def initialize(rows={}, &block) @map = rows @unmapped = Hash.new if block_given? DSL.new(self).instance_eval(&block) end freeze end |
Instance Method Details
#[](key) ⇒ Attribute
Retrieve an attribute by symbolic name
51 52 53 |
# File 'lib/stockboy/attribute_map.rb', line 51 def [](key) @map[key] end |
#attribute_from(key) ⇒ Attribute
Fetch the attribute corresponding to the source field name
60 61 62 |
# File 'lib/stockboy/attribute_map.rb', line 60 def attribute_from(key) find { |a| a.from == key } or @unmapped[key] ||= Attribute.new(nil, key, nil) end |
#each(*args) {|| ... } ⇒ Enumerator
Enumerate over attributes
69 70 71 |
# File 'lib/stockboy/attribute_map.rb', line 69 def each(*args, &block) @map.values.each(*args, &block) end |