class SimpleModelView::ValueFormatter

Attributes

options[R]
value[R]

Public Instance Methods

call(value, type, options) click to toggle source
# File lib/simple_model_view/value_formatter.rb, line 7
def call(value, type, options)
  @value = value
  @options = options
  public_send "format_#{type}"
end
format_boolean() click to toggle source
# File lib/simple_model_view/value_formatter.rb, line 17
def format_boolean
  I18n.t "simple_model_view.formats.boolean.#{value}"
end
format_date() click to toggle source
# File lib/simple_model_view/value_formatter.rb, line 21
def format_date
  case options[:format]
  when Symbol
    I18n.l value, format: options[:format]

  when String
    value.strftime options[:format]

  else
    I18n.l value
  end
end
Also aliased as: format_time
format_float() click to toggle source
# File lib/simple_model_view/value_formatter.rb, line 40
def format_float
  value_format 'float'
end
format_html() click to toggle source
# File lib/simple_model_view/value_formatter.rb, line 44
def format_html
  raise NotImplementedError, '`html` is not implemented yet'
end
format_id() click to toggle source
# File lib/simple_model_view/value_formatter.rb, line 13
def format_id
  value.to_s
end
format_inspect() click to toggle source
# File lib/simple_model_view/value_formatter.rb, line 52
def format_inspect
  value.inspect
end
format_integer() click to toggle source
# File lib/simple_model_view/value_formatter.rb, line 36
def format_integer
  value_format 'integer'
end
format_md() click to toggle source
# File lib/simple_model_view/value_formatter.rb, line 48
def format_md
  raise NotImplementedError, '`md` is not implemented yet'
end
format_object() click to toggle source
# File lib/simple_model_view/value_formatter.rb, line 56
def format_object
  value.to_s
end
format_string() click to toggle source
# File lib/simple_model_view/value_formatter.rb, line 60
def format_string
  value.to_s
end
format_time()
Alias for: format_date

Private Instance Methods

fetch_format_string(format, path) click to toggle source
# File lib/simple_model_view/value_formatter.rb, line 71
def fetch_format_string(format, path)
  return unless format
  return I18n.t(format, scope: path) if format.is_a?(Symbol)
  format.to_s
end
value_format(type) click to toggle source
# File lib/simple_model_view/value_formatter.rb, line 66
def value_format(type)
  format_string = fetch_format_string options[:format], "simple_model_view.formats.#{type}"
  format_string ? format_string % value : value.to_s
end