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
Public Class Methods
Source
# File lib/ice_cube/validated_rule.rb, line 26 def initialize(interval = 1) @validations = {} end
Public Instance Methods
Source
# File lib/ice_cube/validated_rule.rb, line 37 def base_interval_validation @validations[:interval].first end
Source
# File lib/ice_cube/validated_rule.rb, line 111 def clobber_base_validations(*types) types.each do |type| @validations.delete(:"base_#{type}") end end
Remove the specified base validations
Source
# File lib/ice_cube/validated_rule.rb, line 62 def full_required? !occurrence_count.nil? end
Source
# File lib/ice_cube/validated_rule.rb, line 47 def next_time(time, start_time, closing_time) @time = time @start_time ||= realign(time, start_time) @time = @start_time if @time < @start_time return nil unless find_acceptable_time_before(closing_time) @uses += 1 if @time @time end
Compute the next time after (or including) the specified time in respect to the given start time
Source
# File lib/ice_cube/validated_rule.rb, line 41 def other_interval_validations Array(@validations[base_interval_validation.type]) end
Source
# File lib/ice_cube/validated_rule.rb, line 58 def realign(opening_time, start_time) start_time end
Source
# File lib/ice_cube/validated_rule.rb, line 102 def replace_validations_for(key, arr) if arr.nil? @validations.delete(key) else @validations[key] = arr end end
Fully replace validations
Source
# File lib/ice_cube/validated_rule.rb, line 31 def reset @time = nil @start_time = nil @uses = 0 end
Reset the uses on the rule to 0
Source
# File lib/ice_cube/validated_rule.rb, line 76 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
Source
# File lib/ice_cube/validated_rule.rb, line 86 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
Source
# File lib/ice_cube/validated_rule.rb, line 66 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
Source
# File lib/ice_cube/validated_rule.rb, line 97 def validations_for(key) @validations[key] ||= [] end
Get the collection that contains validations of a certain type
Private Instance Methods
Source
# File lib/ice_cube/validated_rule.rb, line 131 def find_acceptable_time_before(boundary) until finds_acceptable_time? return false if past_closing_time?(boundary) end true end
Source
# File lib/ice_cube/validated_rule.rb, line 125 def finds_acceptable_time? validation_names.all? do |type| validation_accepts_or_updates_time?(@validations[type]) end end
Source
# File lib/ice_cube/validated_rule.rb, line 119 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
Source
# File lib/ice_cube/validated_rule.rb, line 169 def past_closing_time?(closing_time) closing_time && @time > closing_time end
Source
# File lib/ice_cube/validated_rule.rb, line 151 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
Source
# File lib/ice_cube/validated_rule.rb, line 141 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
Returns true if all validations for the current rule match otherwise false and shifts to the first (largest) unmatched offset
Source
# File lib/ice_cube/validated_rule.rb, line 173 def validation_names VALIDATION_ORDER & @validations.keys end
Source
# File lib/ice_cube/validated_rule.rb, line 177 def verify_alignment(value, freq, rule_part) InputAlignment.new(self, value, rule_part).verify(freq) do |error| yield error end end