Class: SimpleParams::Formatter

Inherits:
Object
  • Object
show all
Extended by:
ActiveSupport::Concern
Defined in:
lib/simple_params/formatter.rb

Instance Method Summary collapse

Constructor Details

#initialize(attribute, formatter) ⇒ Formatter

Returns a new instance of Formatter.



7
8
9
10
# File 'lib/simple_params/formatter.rb', line 7

def initialize(attribute, formatter)
  @attribute = attribute
  @formatter = formatter
end

Instance Method Details

#format(value) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/simple_params/formatter.rb', line 12

def format(value)
  if @formatter.is_a?(Proc)
    @formatter.call(@attribute, value)
  else
    @attribute.send(@formatter, value)
  end
end