class Repeatable::Expression::RangeInYear

Attributes

end_day[R]
end_month[R]
start_day[R]
start_month[R]

Public Class Methods

new(start_month:, end_month: start_month, start_day: 0, end_day: 0) click to toggle source
# 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

Public Instance Methods

include?(date) click to toggle source
# 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() click to toggle source
# 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

Private Instance Methods

end_month_include?(date) click to toggle source
# File lib/repeatable/expression/range_in_year.rb, line 41
def end_month_include?(date)
  date.month == end_month && (end_day == 0 || date.day <= end_day)
end
months_include?(date) click to toggle source
# File lib/repeatable/expression/range_in_year.rb, line 33
def months_include?(date)
  date.month > start_month && date.month < end_month
end
start_month_include?(date) click to toggle source
# File lib/repeatable/expression/range_in_year.rb, line 37
def start_month_include?(date)
  date.month == start_month && (start_day == 0 || date.day >= start_day)
end