Class: HumanAttributes::Formatters::Custom
- Defined in:
- lib/human_attributes/formatters/custom.rb
Constant Summary
Constants included from Config
Instance Attribute Summary collapse
-
#formatter ⇒ Object
readonly
Returns the value of attribute formatter.
Attributes inherited from Base
#attribute, #default, #options, #suffix, #type
Instance Method Summary collapse
- #apply(instance, value) ⇒ Object
-
#initialize(attribute, type, options) ⇒ Custom
constructor
A new instance of Custom.
Methods inherited from Base
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, ) @formatter = [:formatter] raise_error('MissingFormatterOption') unless formatter.is_a?(Proc) super end |
Instance Attribute Details
#formatter ⇒ Object (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 |