Class: Repeatable::Expression::RangeInYear

Inherits:
Date
  • Object
show all
Defined in:
lib/repeatable/expression/range_in_year.rb

Instance Method Summary collapse

Methods inherited from Date

#==, #hash

Methods inherited from Base

===

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

Returns:

  • (Boolean)


11
12
13
# File 'lib/repeatable/expression/range_in_year.rb', line 11

def include?(date)
  months_include?(date) || start_month_include?(date) || end_month_include?(date)
end

#to_hObject



15
16
17
18
19
20
21
# File 'lib/repeatable/expression/range_in_year.rb', line 15

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