Class: Attrocity::AttributeTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/attrocity/attributes/attribute_template.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#coercerObject (readonly)

Returns the value of attribute coercer.



4
5
6
# File 'lib/attrocity/attributes/attribute_template.rb', line 4

def coercer
  @coercer
end

#mapperObject (readonly)

Returns the value of attribute mapper.



4
5
6
# File 'lib/attrocity/attributes/attribute_template.rb', line 4

def mapper
  @mapper
end

#nameObject (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