Class: DateRangeFormatter::Formatter
- Inherits:
-
Object
- Object
- DateRangeFormatter::Formatter
- Defined in:
- lib/date_range_formatter.rb
Instance Attribute Summary collapse
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#from_date ⇒ Object
readonly
Returns the value of attribute from_date.
-
#until_date ⇒ Object
readonly
Returns the value of attribute until_date.
Instance Method Summary collapse
-
#initialize(from_date, until_date, format) ⇒ Formatter
constructor
A new instance of Formatter.
- #same_days? ⇒ Boolean
- #same_hours? ⇒ Boolean
- #same_months? ⇒ Boolean
- #same_years? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(from_date, until_date, format) ⇒ Formatter
Returns a new instance of Formatter.
27 28 29 30 31 |
# File 'lib/date_range_formatter.rb', line 27 def initialize(from_date, until_date, format) @from_date = from_date @until_date = until_date @format = format.to_sym end |
Instance Attribute Details
#format ⇒ Object (readonly)
Returns the value of attribute format.
25 26 27 |
# File 'lib/date_range_formatter.rb', line 25 def format @format end |
#from_date ⇒ Object (readonly)
Returns the value of attribute from_date.
25 26 27 |
# File 'lib/date_range_formatter.rb', line 25 def from_date @from_date end |
#until_date ⇒ Object (readonly)
Returns the value of attribute until_date.
25 26 27 |
# File 'lib/date_range_formatter.rb', line 25 def until_date @until_date end |
Instance Method Details
#same_days? ⇒ Boolean
45 46 47 |
# File 'lib/date_range_formatter.rb', line 45 def same_days? same_months? && from_date.day == until_date.day end |
#same_hours? ⇒ Boolean
41 42 43 |
# File 'lib/date_range_formatter.rb', line 41 def same_hours? same_days? && from_date.hour == until_date.hour end |
#same_months? ⇒ Boolean
49 50 51 |
# File 'lib/date_range_formatter.rb', line 49 def same_months? same_years? && from_date.month == until_date.month end |
#same_years? ⇒ Boolean
53 54 55 |
# File 'lib/date_range_formatter.rb', line 53 def same_years? from_date.year == until_date.year end |
#to_s ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/date_range_formatter.rb', line 33 def to_s return I18n.t 'same_hours', same_hours_data.merge(scope: ['date_range', format]) if same_hours? return I18n.t 'same_days', same_days_data.merge(scope: ['date_range', format]) if same_days? return I18n.t 'same_months', same_months_data.merge(scope: ['date_range', format]) if same_months? return I18n.t 'same_years', same_years_data.merge(scope: ['date_range', format]) if same_years? I18n.t 'different_components', different_components_data.merge(scope: ['date_range', format]) end |