Module: Resubject::Extensions::TemplateMethods
- Included in:
- Presenter
- Defined in:
- lib/resubject/extensions/template_methods.rb
Overview
All Rails extensions
Instance Method Summary collapse
-
#currency(attribute, options = {}) ⇒ Object
Generates an attribute using ‘number_to_currency` helper from rails.
-
#date_format(attribute, format = :default) ⇒ Object
Formats a date/time attribtue using ‘to_s` helper from ActiveSupport::TimeWithZone.
-
#percentage(attribute, options = {}) ⇒ Object
Generates an attribute using ‘number_to_percentage` helper from rails.
-
#time_ago(attribute, include_seconds = false) ⇒ Object
Generates an attribute using ‘time_ago_in_words` helper from rails.
Instance Method Details
#currency(attribute, options = {}) ⇒ Object
Generates an attribute using ‘number_to_currency` helper from rails
28 29 30 31 32 |
# File 'lib/resubject/extensions/template_methods.rb', line 28 def currency(attribute, = {}) define_method attribute do template.number_to_currency to_model.send(attribute), end end |
#date_format(attribute, format = :default) ⇒ Object
Formats a date/time attribtue using ‘to_s` helper from ActiveSupport::TimeWithZone
116 117 118 119 120 121 |
# File 'lib/resubject/extensions/template_methods.rb', line 116 def date_format(attribute, format = :default) define_method attribute do return if to_model.send(attribute).nil? to_model.send(attribute).to_s(format) end end |
#percentage(attribute, options = {}) ⇒ Object
Generates an attribute using ‘number_to_percentage` helper from rails
84 85 86 87 88 |
# File 'lib/resubject/extensions/template_methods.rb', line 84 def percentage(attribute, = {}) define_method attribute do template.number_to_percentage to_model.send(attribute), end end |
#time_ago(attribute, include_seconds = false) ⇒ Object
Generates an attribute using ‘time_ago_in_words` helper from rails
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/resubject/extensions/template_methods.rb', line 49 def time_ago(attribute, include_seconds = false) if Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new('4') define_method attribute do return if to_model.send(attribute).nil? template.time_ago_in_words to_model.send(attribute), include_seconds end else define_method attribute do return if to_model.send(attribute).nil? template.time_ago_in_words to_model.send(attribute), include_seconds: include_seconds end end end |