Class: IceCube::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/ice_cube/rule.rb

Direct Known Subclasses

SingleOccurrenceRule, ValidatedRule

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#usesObject (readonly)

Returns the value of attribute uses.



7
8
9
# File 'lib/ice_cube/rule.rb', line 7

def uses
  @uses
end

Class Method Details

.daily(interval = 1) ⇒ Object

Daily Rule



100
101
102
# File 'lib/ice_cube/rule.rb', line 100

def daily(interval = 1)
  DailyRule.new(interval)
end

.from_hash(original_hash) ⇒ Object

Convert from a hash and create a rule



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ice_cube/rule.rb', line 50

def self.from_hash(original_hash)
  hash = IceCube::FlexibleHash.new original_hash
  return nil unless match = hash[:rule_type].match(/\:\:(.+?)Rule/)
  rule = IceCube::Rule.send(match[1].downcase.to_sym, hash[:interval] || 1)
  rule.interval(hash[:interval] || 1, TimeUtil.wday_to_sym(hash[:week_start] || 0)) if match[1] == "Weekly"
  rule.until(TimeUtil.deserialize_time(hash[:until])) if hash[:until]
  rule.count(hash[:count]) if hash[:count]
  hash[:validations] && hash[:validations].each do |key, value|
    key = key.to_sym unless key.is_a?(Symbol)
    value.is_a?(Array) ? rule.send(key, *value) : rule.send(key, value)
  end
  rule
end

.from_ical(ical) ⇒ Object

Convert from ical string and create a rule



31
32
33
# File 'lib/ice_cube/rule.rb', line 31

def self.from_ical(ical)
  IceCube::IcalParser.rule_from_ical(ical)
end

.from_yaml(yaml) ⇒ Object

From yaml



41
42
43
# File 'lib/ice_cube/rule.rb', line 41

def self.from_yaml(yaml)
  from_hash YAML::load(yaml)
end

.hourly(interval = 1) ⇒ Object

Hourly Rule



95
96
97
# File 'lib/ice_cube/rule.rb', line 95

def hourly(interval = 1)
  HourlyRule.new(interval)
end

.minutely(interval = 1) ⇒ Object

Minutely Rule



90
91
92
# File 'lib/ice_cube/rule.rb', line 90

def minutely(interval = 1)
  MinutelyRule.new(interval)
end

.monthly(interval = 1) ⇒ Object

Monthly Rule



110
111
112
# File 'lib/ice_cube/rule.rb', line 110

def monthly(interval = 1)
  MonthlyRule.new(interval)
end

.secondly(interval = 1) ⇒ Object

Secondly Rule



85
86
87
# File 'lib/ice_cube/rule.rb', line 85

def secondly(interval = 1)
  SecondlyRule.new(interval)
end

.weekly(interval = 1, week_start = :sunday) ⇒ Object

Weekly Rule



105
106
107
# File 'lib/ice_cube/rule.rb', line 105

def weekly(interval = 1, week_start = :sunday)
  WeeklyRule.new(interval, week_start)
end

.yearly(interval = 1) ⇒ Object

Yearly Rule



115
116
117
# File 'lib/ice_cube/rule.rb', line 115

def yearly(interval = 1)
  YearlyRule.new(interval)
end

Instance Method Details

#==(rule) ⇒ Object



14
15
16
17
18
19
# File 'lib/ice_cube/rule.rb', line 14

def ==(rule)
  if rule.is_a? Rule
    hash = to_hash
    hash && hash == rule.to_hash
  end
end

#full_required?Boolean

Whether this rule requires a full run

Returns:

  • (Boolean)


77
78
79
# File 'lib/ice_cube/rule.rb', line 77

def full_required?
  !@count.nil?
end

#hashObject



21
22
23
24
# File 'lib/ice_cube/rule.rb', line 21

def hash
  h = to_hash
  h.nil? ? super : h.hash
end

#next_time(time, schedule, closing_time) ⇒ Object



69
70
# File 'lib/ice_cube/rule.rb', line 69

def next_time(time, schedule, closing_time)
end

#on?(time, schedule) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/ice_cube/rule.rb', line 72

def on?(time, schedule)
  next_time(time, schedule, time).to_i == time.to_i
end

#resetObject

Reset the uses on the rule to 0



65
66
67
# File 'lib/ice_cube/rule.rb', line 65

def reset
  @uses = 0
end

#terminating?Boolean

Is this a terminating schedule?

Returns:

  • (Boolean)


10
11
12
# File 'lib/ice_cube/rule.rb', line 10

def terminating?
  until_time || occurrence_count
end

#to_hashObject

Raises:

  • (MethodNotImplemented)


45
46
47
# File 'lib/ice_cube/rule.rb', line 45

def to_hash
  raise MethodNotImplemented, "Expected to be overridden by subclasses"
end

#to_icalObject

Raises:

  • (MethodNotImplemented)


26
27
28
# File 'lib/ice_cube/rule.rb', line 26

def to_ical
  raise MethodNotImplemented, "Expected to be overrridden by subclasses"
end

#to_yaml(*args) ⇒ Object

Yaml implementation



36
37
38
# File 'lib/ice_cube/rule.rb', line 36

def to_yaml(*args)
  YAML::dump(to_hash, *args)
end