Class: IceCube::WeeklyRule
- Inherits:
-
ValidatedRule
- Object
- Rule
- ValidatedRule
- IceCube::WeeklyRule
- Includes:
- 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
Calculate the effective start time for when the given start time is later in the week than one of the weekday validations, such that times could be missed by a 7-day jump using the weekly interval, or when selecting from a date that is misaligned from the schedule interval.
- #wday_offset(step_time, start_time) ⇒ Object
Methods included from Validations::WeeklyInterval
Methods inherited from ValidatedRule
#base_interval_type, #base_interval_validation, #clobber_base_validations, #dst_adjust?, #next_time, #other_interval_validations, #replace_validations_for, #reset, #skipped_for_dst, #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::DayOfYear
Methods included from Validations::MonthOfYear
Methods included from Validations::Day
Methods included from Validations::DayOfWeek
Methods included from Validations::DayOfMonth
Methods included from Validations::SecondOfMinute
Methods included from Validations::MinuteOfHour
Methods included from Validations::HourOfDay
Methods included from Validations::ScheduleLock
Methods inherited from Rule
#==, daily, from_hash, from_ical, from_yaml, #full_required?, #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.
9 10 11 12 13 14 |
# File 'lib/ice_cube/rules/weekly_rule.rb', line 9 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.
7 8 9 |
# File 'lib/ice_cube/rules/weekly_rule.rb', line 7 def week_start @week_start end |
Instance Method Details
#realign(step_time, start_time) ⇒ Object
Calculate the effective start time for when the given start time is later in the week than one of the weekday validations, such that times could be missed by a 7-day jump using the weekly interval, or when selecting from a date that is misaligned from the schedule interval.
21 22 23 24 25 26 |
# File 'lib/ice_cube/rules/weekly_rule.rb', line 21 def realign(step_time, start_time) time = TimeUtil::TimeWrapper.new(start_time) offset = wday_offset(step_time, start_time) time.add(:day, offset) if offset time.to_time end |
#wday_offset(step_time, start_time) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ice_cube/rules/weekly_rule.rb', line 28 def wday_offset(step_time, start_time) wday_validations = other_interval_validations.select { |v| v.type == :wday } return if wday_validations.none? days = (step_time - start_time).to_i / ONE_DAY interval = base_interval_validation.validate(step_time, start_time).to_i min_wday = TimeUtil.normalize_wday(wday_validations.min_by(&:day).day, week_start) step_wday = TimeUtil.normalize_wday(step_time.wday, week_start) days + interval - step_wday + min_wday end |