Class: Attrocity::AttributeTemplate
- Inherits:
-
Object
- Object
- Attrocity::AttributeTemplate
- Defined in:
- lib/attrocity/attributes/attribute_template.rb
Instance Attribute Summary collapse
-
#coercer ⇒ Object
readonly
Returns the value of attribute coercer.
-
#mapper ⇒ Object
readonly
Returns the value of attribute mapper.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name, coercer, mapping) ⇒ AttributeTemplate
constructor
A new instance of AttributeTemplate.
- #mapper_key_for(key) ⇒ Object
- #to_attribute(data) ⇒ Object
Constructor Details
#initialize(name, coercer, mapping) ⇒ AttributeTemplate
Returns a new instance of AttributeTemplate.
6 7 8 9 10 |
# File 'lib/attrocity/attributes/attribute_template.rb', line 6 def initialize(name, coercer, mapping) @name = name @coercer = coercer @mapper = mapping end |
Instance Attribute Details
#coercer ⇒ Object (readonly)
Returns the value of attribute coercer.
4 5 6 |
# File 'lib/attrocity/attributes/attribute_template.rb', line 4 def coercer @coercer end |
#mapper ⇒ Object (readonly)
Returns the value of attribute mapper.
4 5 6 |
# File 'lib/attrocity/attributes/attribute_template.rb', line 4 def mapper @mapper end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/attrocity/attributes/attribute_template.rb', line 4 def name @name end |
Instance Method Details
#mapper_key_for(key) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/attrocity/attributes/attribute_template.rb', line 17 def mapper_key_for(key) key = key.to_s if name.to_s == key || mapper.key.to_s == key mapper.key else nil end end |
#to_attribute(data) ⇒ Object
12 13 14 15 |
# File 'lib/attrocity/attributes/attribute_template.rb', line 12 def to_attribute(data) val = ValueExtractor.new(data, mapper: mapper, coercer: coercer).value Attribute.new(name, val) end |