class IceCube::Rule
Constants
- INTERVAL_TYPES
Attributes
uses[R]
Public Class Methods
daily(interval = 1)
click to toggle source
Daily Rule
# File lib/ice_cube/rule.rb, line 126 def daily(interval = 1) DailyRule.new(interval) end
from_hash(original_hash)
click to toggle source
Convert from a hash and create a rule
# File lib/ice_cube/rule.rb, line 64 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) if match[1] == "Weekly" rule.interval(hash[:interval] || 1, TimeUtil.wday_to_sym(hash[:week_start] || 0)) end rule.until(TimeUtil.deserialize_time(hash[:until])) if hash[:until] rule.count(hash[:count]) if hash[:count] hash[:validations] && hash[:validations].each do |name, args| apply_validation(rule, name, args) end rule end
from_ical(ical)
click to toggle source
Convert from ical string and create a rule
# File lib/ice_cube/rule.rb, line 36 def self.from_ical(ical) IceCube::IcalParser.rule_from_ical(ical) end
from_yaml(yaml)
click to toggle source
From yaml
# File lib/ice_cube/rule.rb, line 46 def self.from_yaml(yaml) from_hash YAML::load(yaml) end
hourly(interval = 1)
click to toggle source
Hourly Rule
# File lib/ice_cube/rule.rb, line 121 def hourly(interval = 1) HourlyRule.new(interval) end
minutely(interval = 1)
click to toggle source
Minutely Rule
# File lib/ice_cube/rule.rb, line 116 def minutely(interval = 1) MinutelyRule.new(interval) end
monthly(interval = 1)
click to toggle source
Monthly Rule
# File lib/ice_cube/rule.rb, line 136 def monthly(interval = 1) MonthlyRule.new(interval) end
secondly(interval = 1)
click to toggle source
Secondly Rule
# File lib/ice_cube/rule.rb, line 111 def secondly(interval = 1) SecondlyRule.new(interval) end
weekly(interval = 1, week_start = :sunday)
click to toggle source
Weekly Rule
# File lib/ice_cube/rule.rb, line 131 def weekly(interval = 1, week_start = :sunday) WeeklyRule.new(interval, week_start) end
yearly(interval = 1)
click to toggle source
Yearly Rule
# File lib/ice_cube/rule.rb, line 141 def yearly(interval = 1) YearlyRule.new(interval) end
Private Class Methods
apply_validation(rule, name, args)
click to toggle source
# File lib/ice_cube/rule.rb, line 95 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
==(other)
click to toggle source
# File lib/ice_cube/rule.rb, line 22 def ==(other) return false unless other.is_a? Rule hash == other.hash end
hash()
click to toggle source
# File lib/ice_cube/rule.rb, line 27 def hash to_hash.hash end
next_time(time, schedule, closing_time)
click to toggle source
# File lib/ice_cube/rule.rb, line 54 def next_time(time, schedule, closing_time) end
on?(time, schedule)
click to toggle source
# File lib/ice_cube/rule.rb, line 57 def on?(time, schedule) next_time(time, schedule, time).to_i == time.to_i end
reset()
click to toggle source
# File lib/ice_cube/rule.rb, line 14 def reset end
terminating?()
click to toggle source
Is this a terminating schedule?
# File lib/ice_cube/rule.rb, line 18 def terminating? until_time || occurrence_count end
to_hash()
click to toggle source
# File lib/ice_cube/rule.rb, line 50 def to_hash raise MethodNotImplemented, "Expected to be overridden by subclasses" end
to_ical()
click to toggle source
# File lib/ice_cube/rule.rb, line 31 def to_ical raise MethodNotImplemented, "Expected to be overridden by subclasses" end
to_yaml(*args)
click to toggle source
Yaml implementation
# File lib/ice_cube/rule.rb, line 41 def to_yaml(*args) YAML::dump(to_hash, *args) end