class Attrocity::AttributeTemplate

Attributes

coercer[R]
mapper[R]
name[R]

Public Class Methods

new(name, coercer, mapping) click to toggle source
# File lib/attrocity/attributes/attribute_template.rb, line 6
def initialize(name, coercer, mapping)
  @name = name
  @coercer = coercer
  @mapper = mapping
end

Public Instance Methods

mapper_key_for(key) click to toggle source
# 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) click to toggle source
# 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