class IceCube::Rule
Constants
- INTERVAL_TYPES
Attributes
Public Class Methods
Source
# File lib/ice_cube/rule.rb, line 118 def daily(interval = 1) DailyRule.new(interval) end
Daily Rule
Source
# File lib/ice_cube/rule.rb, line 61 def from_hash(original_hash) hash = IceCube::FlexibleHash.new original_hash unless hash[:rule_type] && (match = hash[:rule_type].match(/::(.+?)Rule/)) raise ArgumentError, "Invalid rule type" end interval_type = match[1].downcase.to_sym unless INTERVAL_TYPES.include?(interval_type) raise ArgumentError, "Invalid rule frequency type: #{match[1]}" end rule = IceCube::Rule.send(interval_type, hash[:interval] || 1) rule.interval(hash[:interval] || 1, TimeUtil.wday_to_sym(hash[:week_start] || 0)) if rule.is_a? WeeklyRule rule.until(TimeUtil.deserialize_time(hash[:until])) if hash[:until] rule.count(hash[:count]) if hash[:count] hash[:validations]&.each do |name, args| apply_validation(rule, name, args) end rule end
Convert from a hash and create a rule
Source
# File lib/ice_cube/rule.rb, line 34 def self.from_ical(ical) IceCube::IcalParser.rule_from_ical(ical) end
Convert from ical string and create a rule
Source
# File lib/ice_cube/rule.rb, line 44 def self.from_yaml(yaml) from_hash YAML.safe_load(yaml, permitted_classes: [Date, Symbol, Time]) end
From yaml
Source
# File lib/ice_cube/rule.rb, line 113 def hourly(interval = 1) HourlyRule.new(interval) end
Hourly Rule
Source
# File lib/ice_cube/rule.rb, line 108 def minutely(interval = 1) MinutelyRule.new(interval) end
Minutely Rule
Source
# File lib/ice_cube/rule.rb, line 128 def monthly(interval = 1) MonthlyRule.new(interval) end
Monthly Rule
Source
# File lib/ice_cube/rule.rb, line 103 def secondly(interval = 1) SecondlyRule.new(interval) end
Secondly Rule
Source
# File lib/ice_cube/rule.rb, line 123 def weekly(interval = 1, week_start = :sunday) WeeklyRule.new(interval, week_start) end
Weekly Rule
Source
# File lib/ice_cube/rule.rb, line 133 def yearly(interval = 1) YearlyRule.new(interval) end
Yearly Rule
Private Class Methods
Source
# File lib/ice_cube/rule.rb, line 89 def apply_validation(rule, name, args) name = name.to_sym unless ValidatedRule::VALIDATION_ORDER.include?(name) raise ArgumentError, "Invalid rule validation type: #{name}" end args.is_a?(Array) ? rule.send(name, *args) : rule.send(name, args) end
Public Instance Methods
Source
# File lib/ice_cube/rule.rb, line 20 def ==(other) return false unless other.is_a? Rule hash == other.hash end
Source
# File lib/ice_cube/rule.rb, line 52 def next_time(time, schedule, closing_time) end
Source
# File lib/ice_cube/rule.rb, line 55 def on?(time, schedule) next_time(time, schedule, time).to_i == time.to_i end
Source
# File lib/ice_cube/rule.rb, line 16 def terminating? until_time || occurrence_count end
Is this a terminating schedule?
Source
# File lib/ice_cube/rule.rb, line 48 def to_hash raise MethodNotImplemented, "Expected to be overridden by subclasses" end
Source
# File lib/ice_cube/rule.rb, line 29 def to_ical raise MethodNotImplemented, "Expected to be overridden by subclasses" end
Source
# File lib/ice_cube/rule.rb, line 39 def to_yaml(*args) YAML.dump(to_hash, *args) end
Yaml implementation