Class: IceCube::ValidatedRule
- Includes:
- IceCube::Validations::Count, IceCube::Validations::Day, IceCube::Validations::DayOfMonth, IceCube::Validations::DayOfWeek, IceCube::Validations::DayOfYear, IceCube::Validations::HourOfDay, IceCube::Validations::MinuteOfHour, IceCube::Validations::MonthOfYear, IceCube::Validations::ScheduleLock, IceCube::Validations::SecondOfMinute, IceCube::Validations::Until
- Defined in:
- lib/ice_cube/validated_rule.rb
Direct Known Subclasses
DailyRule, HourlyRule, MinutelyRule, MonthlyRule, SecondlyRule, WeeklyRule, YearlyRule
Constant Summary collapse
- VALIDATION_ORDER =
Validations ordered for efficiency in sequence of:
-
descending intervals
-
boundary limits
-
base values by cardinality (n = 60, 60, 31, 24, 12, 7)
-
locks by cardinality (n = 365, 60, 60, 31, 24, 12, 7)
-
interval multiplier
-
[ :year, :month, :day, :wday, :hour, :min, :sec, :count, :until, :base_sec, :base_min, :base_day, :base_hour, :base_month, :base_wday, :day_of_year, :second_of_minute, :minute_of_hour, :day_of_month, :hour_of_day, :month_of_year, :day_of_week, :interval ]
Instance Attribute Summary
Attributes inherited from Rule
Instance Method Summary collapse
-
#clobber_base_validations(*types) ⇒ Object
Remove the specified base validations.
- #dst_adjust? ⇒ Boolean
-
#initialize(interval = 1) ⇒ ValidatedRule
constructor
A new instance of ValidatedRule.
-
#next_time(time, schedule, closing_time) ⇒ Object
Compute the next time after (or including) the specified time in respect to the given schedule.
-
#replace_validations_for(key, arr) ⇒ Object
Fully replace validations.
- #skipped_for_dst ⇒ Object
- #to_hash ⇒ Object
- #to_ical ⇒ Object
- #to_s ⇒ Object
-
#validations_for(key) ⇒ Object
Get the collection that contains validations of a certain type.
Methods included from IceCube::Validations::Until
Methods included from Deprecated
#deprecated, #deprecated_alias, schedule_options
Methods included from IceCube::Validations::Count
Methods included from IceCube::Validations::DayOfYear
Methods included from IceCube::Validations::MonthOfYear
Methods included from IceCube::Validations::Day
Methods included from IceCube::Validations::DayOfWeek
Methods included from IceCube::Validations::DayOfMonth
Methods included from IceCube::Validations::SecondOfMinute
Methods included from IceCube::Validations::MinuteOfHour
Methods included from IceCube::Validations::HourOfDay
Methods included from IceCube::Validations::ScheduleLock
Methods inherited from Rule
#==, daily, from_hash, from_yaml, #full_required?, #hash, hourly, minutely, monthly, #on?, #reset, secondly, #terminating?, #to_yaml, weekly, yearly
Constructor Details
#initialize(interval = 1) ⇒ ValidatedRule
Returns a new instance of ValidatedRule.
33 34 35 |
# File 'lib/ice_cube/validated_rule.rb', line 33 def initialize(interval = 1, *) @validations = Hash.new end |
Instance Method Details
#clobber_base_validations(*types) ⇒ Object
Remove the specified base validations
102 103 104 105 106 |
# File 'lib/ice_cube/validated_rule.rb', line 102 def clobber_base_validations(*types) types.each do |type| @validations.delete(:"base_#{type}") end end |
#dst_adjust? ⇒ Boolean
53 54 55 |
# File 'lib/ice_cube/validated_rule.rb', line 53 def dst_adjust? @validations[:interval].any? &:dst_adjust? end |
#next_time(time, schedule, closing_time) ⇒ Object
Compute the next time after (or including) the specified time in respect to the given schedule
39 40 41 42 43 44 45 46 47 |
# File 'lib/ice_cube/validated_rule.rb', line 39 def next_time(time, schedule, closing_time) @time = time @schedule = schedule return nil unless find_acceptable_time_before(closing_time) @uses += 1 if @time @time end |
#replace_validations_for(key, arr) ⇒ Object
Fully replace validations
93 94 95 96 97 98 99 |
# File 'lib/ice_cube/validated_rule.rb', line 93 def replace_validations_for(key, arr) if arr.nil? @validations.delete(key) else @validations[key] = arr end end |
#skipped_for_dst ⇒ Object
49 50 51 |
# File 'lib/ice_cube/validated_rule.rb', line 49 def skipped_for_dst @uses -= 1 if @uses > 0 end |
#to_hash ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/ice_cube/validated_rule.rb', line 67 def to_hash builder = HashBuilder.new(self) @validations.each do |name, validations| validations.each do |validation| validation.build_hash(builder) end end builder.to_hash end |
#to_ical ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/ice_cube/validated_rule.rb', line 77 def to_ical builder = IcalBuilder.new @validations.each do |name, validations| validations.each do |validation| validation.build_ical(builder) end end builder.to_s end |
#to_s ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/ice_cube/validated_rule.rb', line 57 def to_s builder = StringBuilder.new @validations.each do |name, validations| validations.each do |validation| validation.build_s(builder) end end builder.to_s end |
#validations_for(key) ⇒ Object
Get the collection that contains validations of a certain type
88 89 90 |
# File 'lib/ice_cube/validated_rule.rb', line 88 def validations_for(key) @validations[key] ||= [] end |