Class: HumanAttributes::Formatters::Base
- Inherits:
-
Object
- Object
- HumanAttributes::Formatters::Base
- Includes:
- Config
- Defined in:
- lib/human_attributes/formatters/base.rb
Constant Summary
Constants included from Config
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#suffix ⇒ Object
readonly
Returns the value of attribute suffix.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #apply(_instance, _value) ⇒ Object
-
#initialize(attribute, type, options) ⇒ Base
constructor
A new instance of Base.
- #method_name ⇒ Object
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) ⇒ Base
Returns a new instance of Base.
8 9 10 11 12 13 14 |
# File 'lib/human_attributes/formatters/base.rb', line 8 def initialize(attribute, type, ) @attribute = attribute.to_sym @type = type.to_sym @default = [:default] @suffix = [:suffix] @options = end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
6 7 8 |
# File 'lib/human_attributes/formatters/base.rb', line 6 def attribute @attribute end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
6 7 8 |
# File 'lib/human_attributes/formatters/base.rb', line 6 def default @default end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/human_attributes/formatters/base.rb', line 6 def @options end |
#suffix ⇒ Object (readonly)
Returns the value of attribute suffix.
6 7 8 |
# File 'lib/human_attributes/formatters/base.rb', line 6 def suffix @suffix end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/human_attributes/formatters/base.rb', line 6 def type @type end |
Instance Method Details
#apply(_instance, _value) ⇒ Object
22 23 24 |
# File 'lib/human_attributes/formatters/base.rb', line 22 def apply(_instance, _value) raise_error('NotImplemented') end |
#method_name ⇒ Object
16 17 18 19 20 |
# File 'lib/human_attributes/formatters/base.rb', line 16 def method_name return "human_#{attribute}" if suffix.blank? return "#{attribute}_#{suffix_by_type(type)}" if suffix == true "#{attribute}_#{suffix}" end |