Class: IceCube::WeeklyRule
- Inherits:
-
ValidatedRule
- Object
- Rule
- ValidatedRule
- IceCube::WeeklyRule
- Includes:
- Validations::Day, Validations::DayOfWeek, Validations::HourOfDay, Validations::MinuteOfHour, Validations::MonthOfYear, Validations::SecondOfMinute, Validations::WeeklyInterval
- Defined in:
- lib/ice_cube/rules/weekly_rule.rb
Constant Summary
Constants inherited from ValidatedRule
ValidatedRule::VALIDATION_ORDER
Constants inherited from Rule
Instance Attribute Summary collapse
-
#week_start ⇒ Object
readonly
Returns the value of attribute week_start.
Attributes inherited from ValidatedRule
Attributes inherited from Rule
Instance Method Summary collapse
-
#initialize(interval = 1, week_start = :sunday) ⇒ WeeklyRule
constructor
A new instance of WeeklyRule.
-
#realign(step_time, start_time) ⇒ Object
Move the effective start time to correct for when the schedule has validations earlier in the week than the selected start time, e.g.
-
#wday_offset(step_time, start_time) ⇒ Object
Calculate how many days to the first wday validation in the correct interval week.
Methods included from Validations::WeeklyInterval
Methods included from Validations::MonthOfYear
Methods included from Validations::Day
Methods included from Validations::DayOfWeek
Methods included from Validations::SecondOfMinute
Methods included from Validations::MinuteOfHour
Methods included from Validations::HourOfDay
Methods inherited from ValidatedRule
#base_interval_validation, #clobber_base_validations, #full_required?, #next_time, #other_interval_validations, #replace_validations_for, #reset, #to_hash, #to_ical, #to_s, #validations_for
Methods included from Validations::Until
Methods included from Deprecated
#deprecated, #deprecated_alias, schedule_options
Methods included from Validations::Count
Methods included from Validations::ScheduleLock
Methods inherited from Rule
#==, daily, from_hash, from_ical, from_yaml, #hash, hourly, minutely, monthly, #next_time, #on?, #reset, secondly, #terminating?, #to_hash, #to_ical, #to_yaml, weekly, yearly
Constructor Details
#initialize(interval = 1, week_start = :sunday) ⇒ WeeklyRule
Returns a new instance of WeeklyRule.
16 17 18 19 20 21 |
# File 'lib/ice_cube/rules/weekly_rule.rb', line 16 def initialize(interval = 1, week_start = :sunday) super(interval) interval(interval, week_start) schedule_lock(:wday, :hour, :min, :sec) reset end |
Instance Attribute Details
#week_start ⇒ Object (readonly)
Returns the value of attribute week_start.
14 15 16 |
# File 'lib/ice_cube/rules/weekly_rule.rb', line 14 def week_start @week_start end |
Instance Method Details
#realign(step_time, start_time) ⇒ Object
Move the effective start time to correct for when the schedule has validations earlier in the week than the selected start time, e.g.
Schedule.new(wednesday).weekly(2).day(:monday)
The effective start time gets realigned to the second next Monday, jumping over the gap week for the interval (2). Without realignment, the correct Monday occurrence would be missed when the schedule performs a 7-day jump into the next interval week, arriving on the Wednesday. This corrects any selections from dates that are misaligned to the schedule interval.
34 35 36 37 38 39 |
# File 'lib/ice_cube/rules/weekly_rule.rb', line 34 def realign(step_time, start_time) time = TimeUtil::TimeWrapper.new(start_time) offset = wday_offset(step_time, start_time) time.add(:day, offset) super(step_time, time.to_time) end |
#wday_offset(step_time, start_time) ⇒ Object
Calculate how many days to the first wday validation in the correct interval week. This may move backwards within the week if starting in an interval week with earlier validations.
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ice_cube/rules/weekly_rule.rb', line 45 def wday_offset(step_time, start_time) return 0 if step_time == start_time wday_validations = other_interval_validations.select { |v| v.type == :wday } return 0 if wday_validations.none? days = step_time.to_date - start_time.to_date interval = base_interval_validation.validate(step_time, start_time).to_i min_wday = wday_validations.map { |v| TimeUtil.normalize_wday(v.day, week_start) }.min step_wday = TimeUtil.normalize_wday(step_time.wday, week_start) days + interval - step_wday + min_wday end |