Class: SimpleModelView::ValueFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_model_view/value_formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/simple_model_view/value_formatter.rb', line 5

def options
  @options
end

#valueObject (readonly)

Returns the value of attribute value.



5
6
7
# File 'lib/simple_model_view/value_formatter.rb', line 5

def value
  @value
end

Instance Method Details

#call(value, type, options) ⇒ Object



7
8
9
10
11
# 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_booleanObject



17
18
19
# File 'lib/simple_model_view/value_formatter.rb', line 17

def format_boolean
  I18n.t "simple_model_view.formats.boolean.#{value}"
end

#format_dateObject Also known as: format_time



21
22
23
24
25
26
27
28
29
30
31
32
# 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

#format_floatObject



40
41
42
# File 'lib/simple_model_view/value_formatter.rb', line 40

def format_float
  value_format 'float'
end

#format_htmlObject

Raises:

  • (NotImplementedError)


44
45
46
# File 'lib/simple_model_view/value_formatter.rb', line 44

def format_html
  raise NotImplementedError, '`html` is not implemented yet'
end

#format_idObject



13
14
15
# File 'lib/simple_model_view/value_formatter.rb', line 13

def format_id
  value.to_s
end

#format_inspectObject



52
53
54
# File 'lib/simple_model_view/value_formatter.rb', line 52

def format_inspect
  value.inspect
end

#format_integerObject



36
37
38
# File 'lib/simple_model_view/value_formatter.rb', line 36

def format_integer
  value_format 'integer'
end

#format_mdObject

Raises:

  • (NotImplementedError)


48
49
50
# File 'lib/simple_model_view/value_formatter.rb', line 48

def format_md
  raise NotImplementedError, '`md` is not implemented yet'
end

#format_objectObject



56
57
58
# File 'lib/simple_model_view/value_formatter.rb', line 56

def format_object
  value.to_s
end

#format_stringObject



60
61
62
# File 'lib/simple_model_view/value_formatter.rb', line 60

def format_string
  value.to_s
end