Class: SimpleModelView::ValueFormatter
- Inherits:
-
Object
- Object
- SimpleModelView::ValueFormatter
- Defined in:
- lib/simple_model_view/value_formatter.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #call(value, type, options) ⇒ Object
- #format_boolean ⇒ Object
- #format_date ⇒ Object (also: #format_time)
- #format_float ⇒ Object
- #format_html ⇒ Object
- #format_id ⇒ Object
- #format_inspect ⇒ Object
- #format_integer ⇒ Object
- #format_md ⇒ Object
- #format_object ⇒ Object
- #format_string ⇒ Object
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/simple_model_view/value_formatter.rb', line 5 def @options end |
#value ⇒ Object (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, ) @value = value @options = public_send "format_#{type}" end |
#format_boolean ⇒ Object
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_date ⇒ Object 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 [:format] when Symbol I18n.l value, format: [:format] when String value.strftime [:format] else I18n.l value end end |
#format_float ⇒ Object
40 41 42 |
# File 'lib/simple_model_view/value_formatter.rb', line 40 def format_float value_format 'float' end |
#format_html ⇒ Object
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_id ⇒ Object
13 14 15 |
# File 'lib/simple_model_view/value_formatter.rb', line 13 def format_id value.to_s end |
#format_inspect ⇒ Object
52 53 54 |
# File 'lib/simple_model_view/value_formatter.rb', line 52 def format_inspect value.inspect end |
#format_integer ⇒ Object
36 37 38 |
# File 'lib/simple_model_view/value_formatter.rb', line 36 def format_integer value_format 'integer' end |
#format_md ⇒ Object
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_object ⇒ Object
56 57 58 |
# File 'lib/simple_model_view/value_formatter.rb', line 56 def format_object value.to_s end |
#format_string ⇒ Object
60 61 62 |
# File 'lib/simple_model_view/value_formatter.rb', line 60 def format_string value.to_s end |