Class: HumanAttributes::Formatters::Base

Inherits:
Object
  • Object
show all
Includes:
Config
Defined in:
lib/human_attributes/formatters/base.rb

Direct Known Subclasses

Boolean, Custom, Date, Datetime, Enumerize, Numeric

Constant Summary

Constants included from Config

Config::TYPES

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options)
  @attribute = attribute.to_sym
  @type = type.to_sym
  @default = options[:default]
  @suffix = options[:suffix]
  @options = options
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



6
7
8
# File 'lib/human_attributes/formatters/base.rb', line 6

def attribute
  @attribute
end

#defaultObject (readonly)

Returns the value of attribute default.



6
7
8
# File 'lib/human_attributes/formatters/base.rb', line 6

def default
  @default
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/human_attributes/formatters/base.rb', line 6

def options
  @options
end

#suffixObject (readonly)

Returns the value of attribute suffix.



6
7
8
# File 'lib/human_attributes/formatters/base.rb', line 6

def suffix
  @suffix
end

#typeObject (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_nameObject



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