Class: Repeatable::Expression::RangeInYear
- Defined in:
- lib/repeatable/expression/range_in_year.rb
Instance Method Summary collapse
- #include?(date) ⇒ Boolean
-
#initialize(start_month:, end_month: start_month, start_day: 0, end_day: 0) ⇒ RangeInYear
constructor
A new instance of RangeInYear.
- #to_h ⇒ Object
Methods inherited from Date
Methods inherited from Base
===, #difference, #intersection, #union
Constructor Details
#initialize(start_month:, end_month: start_month, start_day: 0, end_day: 0) ⇒ RangeInYear
Returns a new instance of RangeInYear.
4 5 6 7 8 9 |
# File 'lib/repeatable/expression/range_in_year.rb', line 4 def initialize(start_month:, end_month: start_month, start_day: 0, end_day: 0) @start_month = start_month @end_month = end_month @start_day = start_day @end_day = end_day end |
Instance Method Details
#include?(date) ⇒ Boolean
11 12 13 14 15 16 17 18 19 |
# File 'lib/repeatable/expression/range_in_year.rb', line 11 def include?(date) return true if months_include?(date) if start_month == end_month start_month_include?(date) && end_month_include?(date) else start_month_include?(date) || end_month_include?(date) end end |
#to_h ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/repeatable/expression/range_in_year.rb', line 21 def to_h args = { start_month: start_month } args[:end_month] = end_month unless end_month == start_month args[:start_day] = start_day unless start_day.zero? args[:end_day] = end_day unless end_day.zero? { range_in_year: args } end |