class IceCube::ValidatedRule
Constants
- 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
-
Attributes
validations[R]
Public Class Methods
new(interval = 1)
click to toggle source
# File lib/ice_cube/validated_rule.rb, line 28 def initialize(interval = 1) @validations = Hash.new end
Public Instance Methods
base_interval_validation()
click to toggle source
# File lib/ice_cube/validated_rule.rb, line 39 def base_interval_validation @validations[:interval].first end
clobber_base_validations(*types)
click to toggle source
Remove the specified base validations
# File lib/ice_cube/validated_rule.rb, line 115 def clobber_base_validations(*types) types.each do |type| @validations.delete(:"base_#{type}") end end
full_required?()
click to toggle source
# File lib/ice_cube/validated_rule.rb, line 66 def full_required? !occurrence_count.nil? end
next_time(time, start_time, closing_time)
click to toggle source
Compute the next time after (or including) the specified time in respect to the given start time
# File lib/ice_cube/validated_rule.rb, line 49 def next_time(time, start_time, closing_time) @time = time unless @start_time @start_time = realign(time, start_time) @time = @start_time if @time < @start_time end return nil unless find_acceptable_time_before(closing_time) @uses += 1 if @time @time end
other_interval_validations()
click to toggle source
# File lib/ice_cube/validated_rule.rb, line 43 def other_interval_validations Array(@validations[base_interval_validation.type]) end
realign(opening_time, start_time)
click to toggle source
# File lib/ice_cube/validated_rule.rb, line 62 def realign(opening_time, start_time) start_time end
replace_validations_for(key, arr)
click to toggle source
Fully replace validations
# File lib/ice_cube/validated_rule.rb, line 106 def replace_validations_for(key, arr) if arr.nil? @validations.delete(key) else @validations[key] = arr end end
reset()
click to toggle source
Reset the uses on the rule to 0
# File lib/ice_cube/validated_rule.rb, line 33 def reset @time = nil @start_time = nil @uses = 0 end
to_hash()
click to toggle source
# File lib/ice_cube/validated_rule.rb, line 80 def to_hash builder = HashBuilder.new(self) @validations.each_value do |validations| validations.each do |validation| validation.build_hash(builder) end end builder.to_hash end
to_ical()
click to toggle source
# File lib/ice_cube/validated_rule.rb, line 90 def to_ical builder = IcalBuilder.new @validations.each_value do |validations| validations.each do |validation| validation.build_ical(builder) end end builder.to_s end
to_s()
click to toggle source
# File lib/ice_cube/validated_rule.rb, line 70 def to_s builder = StringBuilder.new @validations.each_value do |validations| validations.each do |validation| validation.build_s(builder) end end builder.to_s end
validations_for(key)
click to toggle source
Get the collection that contains validations of a certain type
# File lib/ice_cube/validated_rule.rb, line 101 def validations_for(key) @validations[key] ||= [] end
Private Instance Methods
find_acceptable_time_before(boundary)
click to toggle source
# File lib/ice_cube/validated_rule.rb, line 135 def find_acceptable_time_before(boundary) until finds_acceptable_time? return false if past_closing_time?(boundary) end true end
finds_acceptable_time?()
click to toggle source
# File lib/ice_cube/validated_rule.rb, line 129 def finds_acceptable_time? validation_names.all? do |type| validation_accepts_or_updates_time?(@validations[type]) end end
normalized_interval(interval)
click to toggle source
# File lib/ice_cube/validated_rule.rb, line 123 def normalized_interval(interval) int = interval.to_i raise ArgumentError, "'#{interval}' is not a valid input for interval. Please pass a postive integer." unless int > 0 int end
past_closing_time?(closing_time)
click to toggle source
# File lib/ice_cube/validated_rule.rb, line 173 def past_closing_time?(closing_time) closing_time && @time > closing_time end
shift_time_by_validation(res, validation)
click to toggle source
# File lib/ice_cube/validated_rule.rb, line 155 def shift_time_by_validation(res, validation) return unless (interval = res.min) wrapper = TimeUtil::TimeWrapper.new(@time, validation.dst_adjust?) wrapper.add(validation.type, interval) wrapper.clear_below(validation.type) # Move over DST if blocked, no adjustments if wrapper.to_time <= @time wrapper = TimeUtil::TimeWrapper.new(wrapper.to_time, false) until wrapper.to_time > @time wrapper.add(:min, 10) # smallest interval end end # And then get the correct time out @time = wrapper.to_time end
validation_accepts_or_updates_time?(validations_for_type)
click to toggle source
Returns true if all validations for the current rule match otherwise false and shifts to the first (largest) unmatched offset
# File lib/ice_cube/validated_rule.rb, line 145 def validation_accepts_or_updates_time?(validations_for_type) res = validations_for_type.each_with_object([]) do |validation, offsets| r = validation.validate(@time, @start_time) return true if r.nil? || r == 0 offsets << r end shift_time_by_validation(res, validations_for_type.first) false end
validation_names()
click to toggle source
# File lib/ice_cube/validated_rule.rb, line 177 def validation_names VALIDATION_ORDER & @validations.keys end
verify_alignment(value, freq, rule_part) { |error| ... }
click to toggle source
# File lib/ice_cube/validated_rule.rb, line 181 def verify_alignment(value, freq, rule_part) InputAlignment.new(self, value, rule_part).verify(freq) do |error| yield error end end