Class: Alchemy::Ingredients::DatetimeView
- Defined in:
- app/components/alchemy/ingredients/datetime_view.rb
Constant Summary collapse
- DEFAULT_DATE_FORMAT =
:"alchemy.default"
Instance Attribute Summary collapse
-
#date_format ⇒ Object
readonly
Returns the value of attribute date_format.
Attributes inherited from BaseView
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(ingredient, date_format: nil, html_options: {}) ⇒ DatetimeView
constructor
A new instance of DatetimeView.
Methods inherited from BaseView
Constructor Details
#initialize(ingredient, date_format: nil, html_options: {}) ⇒ DatetimeView
Returns a new instance of DatetimeView.
10 11 12 13 |
# File 'app/components/alchemy/ingredients/datetime_view.rb', line 10 def initialize(ingredient, date_format: nil, html_options: {}) super(ingredient) @date_format = settings_value(:date_format, value: date_format) || DEFAULT_DATE_FORMAT end |
Instance Attribute Details
#date_format ⇒ Object (readonly)
Returns the value of attribute date_format.
6 7 8 |
# File 'app/components/alchemy/ingredients/datetime_view.rb', line 6 def date_format @date_format end |
Instance Method Details
#call ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'app/components/alchemy/ingredients/datetime_view.rb', line 15 def call datetime = ingredient.value.in_time_zone(Rails.application.config.time_zone) if date_format == "rfc822" datetime.to_fs(:rfc822) else ::I18n.l(datetime, format: date_format) end.html_safe end |