Class: Alchemy::Ingredients::DatetimeView

Inherits:
BaseView
  • Object
show all
Defined in:
app/components/alchemy/ingredients/datetime_view.rb

Instance Attribute Summary collapse

Attributes inherited from BaseView

#html_options, #ingredient

Instance Method Summary collapse

Methods inherited from BaseView

#render?

Constructor Details

#initialize(ingredient, date_format: nil, html_options: {}) ⇒ DatetimeView

Returns a new instance of DatetimeView.

Parameters:

  • ingredient (Alchemy::Ingredient)
  • date_format (String) (defaults to: nil)

    The date format to use. Use either a strftime format string, a I18n format symbol or “rfc822”.



8
9
10
11
# File 'app/components/alchemy/ingredients/datetime_view.rb', line 8

def initialize(ingredient, date_format: nil, html_options: {})
  super(ingredient)
  @date_format = settings_value(:date_format, value: date_format)
end

Instance Attribute Details

#date_formatObject (readonly)

Returns the value of attribute date_format.



4
5
6
# File 'app/components/alchemy/ingredients/datetime_view.rb', line 4

def date_format
  @date_format
end

Instance Method Details

#callObject



13
14
15
16
17
18
19
# File 'app/components/alchemy/ingredients/datetime_view.rb', line 13

def call
  if date_format == "rfc822"
    ingredient.value.to_s(:rfc822)
  else
    ::I18n.l(ingredient.value, format: date_format)
  end
end