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

===, #deconstruct_keys, #difference, #intersection, #to_h, #union

Constructor Details

#initialize(start_month:, end_month: start_month, start_day: 0, end_day: 0) ⇒ void

Parameters:

  • start_month (Integer)
  • end_month (Integer) (defaults to: start_month)
  • start_day (Integer) (defaults to: 0)
  • end_day (Integer) (defaults to: 0)


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

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

Parameters:

  • date (::Date)

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
30
# File 'lib/repeatable/expression/range_in_year.rb', line 22

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