Class: IntervalsForHumans::Interval
- Inherits:
-
Object
- Object
- IntervalsForHumans::Interval
- Defined in:
- lib/intervals_for_humans/interval.rb
Instance Method Summary collapse
- #components ⇒ Object
-
#initialize(start_date, end_date) ⇒ Interval
constructor
A new instance of Interval.
- #to_s ⇒ Object
Constructor Details
#initialize(start_date, end_date) ⇒ Interval
Returns a new instance of Interval.
2 3 4 5 6 |
# File 'lib/intervals_for_humans/interval.rb', line 2 def initialize(start_date, end_date) @start_date = start_date @end_date = end_date @date_counter = start_date end |
Instance Method Details
#components ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/intervals_for_humans/interval.rb', line 8 def components @components ||= { year: advance_years!, month: advance_months!, day: advance_days!, } end |
#to_s ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/intervals_for_humans/interval.rb', line 16 def to_s @to_s ||= begin components .each_pair .select { |(_key, value)| value.positive? } .map { |(key, value)| "#{value} #{key}#{'s' if value > 1}" } .join(", ") end end |