Class: HumanAttributes::Formatters::Custom

Inherits:
Base
  • Object
show all
Defined in:
lib/human_attributes/formatters/custom.rb

Constant Summary

Constants included from Config

Config::TYPES

Instance Attribute Summary collapse

Attributes inherited from Base

#attribute, #default, #options, #suffix, #type

Instance Method Summary collapse

Methods inherited from Base

#method_name

Methods included from Config

#category_by_type, #formatter_by_type, #known_type?, #raise_error, #suffix_by_type, #type_config

Constructor Details

#initialize(attribute, type, options) ⇒ Custom

Returns a new instance of Custom.



6
7
8
9
10
# File 'lib/human_attributes/formatters/custom.rb', line 6

def initialize(attribute, type, options)
  @formatter = options[:formatter]
  raise_error('MissingFormatterOption') unless formatter.is_a?(Proc)
  super
end

Instance Attribute Details

#formatterObject (readonly)

Returns the value of attribute formatter.



4
5
6
# File 'lib/human_attributes/formatters/custom.rb', line 4

def formatter
  @formatter
end

Instance Method Details

#apply(instance, value) ⇒ Object



12
13
14
# File 'lib/human_attributes/formatters/custom.rb', line 12

def apply(instance, value)
  formatter.call(instance, value)
end