Class: I18nDateRangeGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n_date_range/i18n_date_range_generator.rb

Overview

Computing range to choose the correct form

Constant Summary collapse

KIND_NO_END =
:no_end
KIND_SAME_DAY =
:same_day
KIND_SAME_MONTH =
:same_month
KIND_SAME_YEAR =
:same_year
KIND_OTHER =
:other

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from_date, to_date = nil, format: :short, layout: :one_line, locale: I18n.locale) ⇒ I18nDateRangeGenerator

“format” can be :short or :long. “layout” can be :one_line or :two_lines



14
15
16
17
18
19
20
# File 'lib/i18n_date_range/i18n_date_range_generator.rb', line 14

def initialize(from_date, to_date = nil, format: :short, layout: :one_line, locale: I18n.locale)
  @from_date = from_date
  @to_date = to_date
  @format = format
  @layout = layout
  @locale = locale
end

Instance Attribute Details

#formatObject (readonly)

Returns the value of attribute format.



5
6
7
# File 'lib/i18n_date_range/i18n_date_range_generator.rb', line 5

def format
  @format
end

#from_dateObject (readonly)

Returns the value of attribute from_date.



5
6
7
# File 'lib/i18n_date_range/i18n_date_range_generator.rb', line 5

def from_date
  @from_date
end

#layoutObject (readonly)

Returns the value of attribute layout.



5
6
7
# File 'lib/i18n_date_range/i18n_date_range_generator.rb', line 5

def layout
  @layout
end

#localeObject (readonly)

Returns the value of attribute locale.



5
6
7
# File 'lib/i18n_date_range/i18n_date_range_generator.rb', line 5

def locale
  @locale
end

#to_dateObject (readonly)

Returns the value of attribute to_date.



5
6
7
# File 'lib/i18n_date_range/i18n_date_range_generator.rb', line 5

def to_date
  @to_date
end

Instance Method Details

#to_sObject



22
23
24
# File 'lib/i18n_date_range/i18n_date_range_generator.rb', line 22

def to_s
  layout == :two_lines && to_formatted.present? ? from_formatted + '<br>' + to_formatted : from_formatted + to_formatted
end