ice_cube 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/ice_cube/builders/string_builder.rb +15 -23
- data/lib/ice_cube/deprecated.rb +33 -23
- data/lib/ice_cube/enumerator.rb +1 -3
- data/lib/ice_cube/errors/count_exceeded.rb +1 -1
- data/lib/ice_cube/errors/until_exceeded.rb +1 -1
- data/lib/ice_cube/flexible_hash.rb +23 -7
- data/lib/ice_cube/formatters/string.rb +155 -0
- data/lib/ice_cube/hash_input.rb +71 -0
- data/lib/ice_cube/occurrence.rb +2 -1
- data/lib/ice_cube/parsers/hash_parser.rb +87 -0
- data/lib/ice_cube/parsers/yaml_parser.rb +21 -0
- data/lib/ice_cube/rule.rb +5 -7
- data/lib/ice_cube/rules/daily_rule.rb +1 -1
- data/lib/ice_cube/rules/hourly_rule.rb +1 -1
- data/lib/ice_cube/rules/minutely_rule.rb +1 -1
- data/lib/ice_cube/rules/monthly_rule.rb +1 -1
- data/lib/ice_cube/rules/secondly_rule.rb +1 -1
- data/lib/ice_cube/rules/yearly_rule.rb +1 -1
- data/lib/ice_cube/schedule.rb +76 -64
- data/lib/ice_cube/string_helpers.rb +10 -0
- data/lib/ice_cube/time_util.rb +24 -8
- data/lib/ice_cube/validated_rule.rb +13 -6
- data/lib/ice_cube/validations/count.rb +8 -6
- data/lib/ice_cube/validations/daily_interval.rb +17 -18
- data/lib/ice_cube/validations/day.rb +8 -4
- data/lib/ice_cube/validations/day_of_month.rb +12 -10
- data/lib/ice_cube/validations/day_of_week.rb +28 -26
- data/lib/ice_cube/validations/day_of_year.rb +15 -12
- data/lib/ice_cube/validations/hour_of_day.rb +13 -11
- data/lib/ice_cube/validations/hourly_interval.rb +18 -21
- data/lib/ice_cube/validations/lock.rb +35 -14
- data/lib/ice_cube/validations/minute_of_hour.rb +13 -11
- data/lib/ice_cube/validations/minutely_interval.rb +16 -19
- data/lib/ice_cube/validations/month_of_year.rb +8 -4
- data/lib/ice_cube/validations/monthly_interval.rb +19 -17
- data/lib/ice_cube/validations/schedule_lock.rb +12 -11
- data/lib/ice_cube/validations/second_of_minute.rb +9 -5
- data/lib/ice_cube/validations/secondly_interval.rb +13 -16
- data/lib/ice_cube/validations/until.rb +16 -12
- data/lib/ice_cube/validations/weekly_interval.rb +24 -23
- data/lib/ice_cube/validations/yearly_interval.rb +14 -11
- data/lib/ice_cube/version.rb +1 -1
- data/lib/ice_cube.rb +13 -11
- data/spec/spec_helper.rb +2 -0
- metadata +24 -34
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: f8d575d65663825eb9be2a82f9e931537009d485
|
|
4
|
+
data.tar.gz: 2e292c2f229a8a7b7aaaf8f8dcaf009412741745
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 98e4ffa4ddc22fb26da6eb632203e389361149216ad62193f64c773fe1a68da07dff80ab3f0470cbc1d0dabfc049780b86eb4f270469b2e47539e46016709c1e
|
|
7
|
+
data.tar.gz: 2882dc6f6af47db013a1ee079c2fc06ecf254274b0d39b00f24bc6a8e72021b4935e27463a65ab7c01740180bcab4236bfc15507825b3db910b4bf16f5ab6ce3
|
|
@@ -13,32 +13,26 @@ module IceCube
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def to_s
|
|
16
|
-
|
|
17
|
-
res = @types.map do |type, segments|
|
|
16
|
+
@types.each_with_object(@base || '') do |(type, segments), str|
|
|
18
17
|
if f = self.class.formatter(type)
|
|
19
|
-
str << ' '
|
|
18
|
+
str << ' ' << f.call(segments)
|
|
20
19
|
else
|
|
21
20
|
next if segments.empty?
|
|
22
|
-
str << ' '
|
|
21
|
+
str << ' ' << self.class.sentence(segments)
|
|
23
22
|
end
|
|
24
23
|
end
|
|
25
|
-
str
|
|
26
24
|
end
|
|
27
25
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
@formatters[type]
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def register_formatter(type, &formatter)
|
|
35
|
-
@formatters ||= {}
|
|
36
|
-
@formatters[type] = formatter
|
|
37
|
-
end
|
|
26
|
+
def self.formatter(type)
|
|
27
|
+
@formatters[type]
|
|
28
|
+
end
|
|
38
29
|
|
|
30
|
+
def self.register_formatter(type, &formatter)
|
|
31
|
+
@formatters ||= {}
|
|
32
|
+
@formatters[type] = formatter
|
|
39
33
|
end
|
|
40
34
|
|
|
41
|
-
|
|
35
|
+
module Helpers
|
|
42
36
|
|
|
43
37
|
NUMBER_SUFFIX = ['th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th']
|
|
44
38
|
SPECIAL_SUFFIX = { 11 => 'th', 12 => 'th', 13 => 'th', 14 => 'th' }
|
|
@@ -54,21 +48,19 @@ module IceCube
|
|
|
54
48
|
end
|
|
55
49
|
|
|
56
50
|
def nice_number(number)
|
|
57
|
-
if number == -1
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
suffix = SPECIAL_SUFFIX.include?(number) ?
|
|
61
|
-
SPECIAL_SUFFIX[number] : NUMBER_SUFFIX[number.abs % 10]
|
|
51
|
+
return 'last' if number == -1
|
|
52
|
+
suffix = SPECIAL_SUFFIX[number] || NUMBER_SUFFIX[number.abs % 10]
|
|
53
|
+
if number < -1
|
|
62
54
|
number.abs.to_s << suffix << ' to last'
|
|
63
55
|
else
|
|
64
|
-
suffix = SPECIAL_SUFFIX.include?(number) ?
|
|
65
|
-
SPECIAL_SUFFIX[number] : NUMBER_SUFFIX[number.abs % 10]
|
|
66
56
|
number.to_s << suffix
|
|
67
57
|
end
|
|
68
58
|
end
|
|
69
59
|
|
|
70
60
|
end
|
|
71
61
|
|
|
62
|
+
extend Helpers
|
|
63
|
+
|
|
72
64
|
end
|
|
73
65
|
|
|
74
66
|
end
|
data/lib/ice_cube/deprecated.rb
CHANGED
|
@@ -1,28 +1,38 @@
|
|
|
1
|
-
module
|
|
1
|
+
module IceCube
|
|
2
|
+
module Deprecated
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
# Define a deprecated alias for a method
|
|
5
|
+
# @param [Symbol] name - name of method to define
|
|
6
|
+
# @param [Symbol] replacement - name of method to replace (alias)
|
|
7
|
+
def deprecated_alias(name, replacement)
|
|
8
|
+
# Create a wrapped version
|
|
9
|
+
define_method(name) do |*args, &block|
|
|
10
|
+
warn "IceCube: ##{name} deprecated (please use ##{replacement})"
|
|
11
|
+
send replacement, *args, &block
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Deprecate a defined method
|
|
16
|
+
# @param [Symbol] name - name of deprecated method
|
|
17
|
+
# @param [Symbol] replacement - name of the desired replacement
|
|
18
|
+
def deprecated(name, replacement)
|
|
19
|
+
# Replace old method
|
|
20
|
+
old_name = :"#{name}_without_deprecation"
|
|
21
|
+
alias_method old_name, name
|
|
22
|
+
# And replace it with a wrapped version
|
|
23
|
+
define_method(name) do |*args, &block|
|
|
24
|
+
warn "IceCube: ##{name} deprecated (please use ##{replacement})"
|
|
25
|
+
send old_name, *args, &block
|
|
26
|
+
end
|
|
27
|
+
end
|
|
13
28
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
alias_method old_name, name
|
|
21
|
-
# And replace it with a wrapped version
|
|
22
|
-
define_method(name) do |*args, &block|
|
|
23
|
-
warn "IceCube: ##{name} deprecated (please use ##{replacement})"
|
|
24
|
-
send old_name, *args, &block
|
|
29
|
+
def self.schedule_options(schedule, options)
|
|
30
|
+
if options[:start_date_override]
|
|
31
|
+
warn "IceCube: :start_date_override option deprecated. " \
|
|
32
|
+
"(please use a block { |s| s.start_time = override })"
|
|
33
|
+
schedule.start_time = options[:start_date_override]
|
|
34
|
+
end
|
|
25
35
|
end
|
|
26
|
-
end
|
|
27
36
|
|
|
37
|
+
end
|
|
28
38
|
end
|
data/lib/ice_cube/enumerator.rb
CHANGED
|
@@ -19,11 +19,9 @@ module IceCube
|
|
|
19
19
|
def find_next
|
|
20
20
|
loop do
|
|
21
21
|
min_time = recurrence_rules.reduce(nil) do |min_time, rule|
|
|
22
|
-
|
|
22
|
+
catch :limit do
|
|
23
23
|
new_time = rule.next_time(time, schedule, min_time || @to_time)
|
|
24
24
|
[min_time, new_time].compact.min
|
|
25
|
-
rescue CountExceeded, UntilExceeded
|
|
26
|
-
min_time
|
|
27
25
|
end
|
|
28
26
|
end
|
|
29
27
|
break nil unless min_time
|
|
@@ -2,21 +2,37 @@ require 'delegate'
|
|
|
2
2
|
|
|
3
3
|
module IceCube
|
|
4
4
|
|
|
5
|
-
#
|
|
5
|
+
# Find keys by symbol or string without symbolizing user input
|
|
6
6
|
# Due to the serialization format of ice_cube, this limited implementation
|
|
7
7
|
# is entirely sufficient
|
|
8
8
|
|
|
9
9
|
class FlexibleHash < SimpleDelegator
|
|
10
10
|
|
|
11
|
-
def
|
|
12
|
-
|
|
11
|
+
def [](key)
|
|
12
|
+
key = _match_key(key)
|
|
13
|
+
super
|
|
13
14
|
end
|
|
14
15
|
|
|
15
|
-
def
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
def fetch(key)
|
|
17
|
+
key = _match_key(key)
|
|
18
|
+
super
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def delete(key)
|
|
22
|
+
key = _match_key(key)
|
|
23
|
+
super
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def _match_key(key)
|
|
29
|
+
return key if __getobj__.has_key? key
|
|
30
|
+
if Symbol == key.class
|
|
31
|
+
__getobj__.keys.detect { |k| return k if k == key.to_s }
|
|
32
|
+
elsif String == key.class
|
|
33
|
+
__getobj__.keys.detect { |k| return k if k.to_s == key }
|
|
19
34
|
end
|
|
35
|
+
key
|
|
20
36
|
end
|
|
21
37
|
|
|
22
38
|
end
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
class IceCube::StringBuilder
|
|
2
|
+
|
|
3
|
+
format :day do |entries|
|
|
4
|
+
case entries = entries.sort
|
|
5
|
+
when [0, 6] then 'on Weekends'
|
|
6
|
+
when [1, 2, 3, 4, 5] then 'on Weekdays'
|
|
7
|
+
else
|
|
8
|
+
"on " << build(:sentence, build(:daynames, entries))
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
format :dayname do |number|
|
|
13
|
+
Date::DAYNAMES[number]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
format :daynames do |entries|
|
|
17
|
+
entries.map { |wday| build(:dayname, wday) + "s" }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
format :monthnames do |entries|
|
|
21
|
+
entries.map { |m| Date::MONTHNAMES[m] }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
format :count do |number|
|
|
25
|
+
times = number == 1 ? "time" : "times"
|
|
26
|
+
"#{number} #{times}"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
format :day_of_month do |entries|
|
|
30
|
+
numbered = build(:sentence, build(:ordinals, entries))
|
|
31
|
+
days = entries.size == 1 ? "day" : "days"
|
|
32
|
+
"on the #{numbered} #{days} of the month"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
format :day_of_week do |entries|
|
|
36
|
+
numbered_weekdays = build(:daynames_of_week, entries).join(" and ")
|
|
37
|
+
"on the #{numbered_weekdays}"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
format :daynames_of_week do |entries|
|
|
41
|
+
entries.map do |occurrence, wday|
|
|
42
|
+
numbered = build(:ordinal, occurrence)
|
|
43
|
+
weekday = build(:dayname, wday)
|
|
44
|
+
"#{numbered} #{weekday}"
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
format :day_of_year do |entries|
|
|
49
|
+
numbered = build(:sentence, build(:ordinals, entries))
|
|
50
|
+
days = entries.size == 1 ? "day" : "days"
|
|
51
|
+
"on the #{numbered} #{days} of the year"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
format :hour_of_day do |entries|
|
|
55
|
+
numbered = build(:sentence, build(:ordinals, entries))
|
|
56
|
+
hours = entries.size == 1 ? "hour" : "hours"
|
|
57
|
+
"on the #{numbered} #{hours} of the day"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
format :minute_of_hour do |entries|
|
|
61
|
+
numbered = build(:sentence, build(:ordinals, entries))
|
|
62
|
+
minutes = entries.size == 1 ? "minute" : "minutes"
|
|
63
|
+
"on the #{numbered} #{minutes} of the hour"
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
format :month_of_year do |entries|
|
|
67
|
+
"in " << build(:sentence, build(:monthnames, entries))
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
format :second_of_minute do |entries|
|
|
71
|
+
numbered = build(:sentence, build(:ordinals, entries))
|
|
72
|
+
seconds = entries.size == 1 ? "second" : "seconds"
|
|
73
|
+
"on the #{numbered} #{seconds} of the minute"
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
format :time do |time|
|
|
77
|
+
time.strftime(IceCube.to_s_time_format)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
format :until do |time|
|
|
81
|
+
"until " << build(:time, time)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
format :sentence do |entries|
|
|
85
|
+
case entries.length
|
|
86
|
+
when 0 then ''
|
|
87
|
+
when 1 then entries[0].to_s
|
|
88
|
+
when 2 then "#{entries[0]} and #{entries[1]}"
|
|
89
|
+
else "#{entries[0...-1].join(', ')}, and #{entries[-1]}"
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
format :ordinals do |entries|
|
|
94
|
+
entries = entries.sort
|
|
95
|
+
entries.rotate! while entries[0] < 0 if entries.last > 0
|
|
96
|
+
entries.map { |number| build(:ordinal, number) }
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
format :ordinal do |number|
|
|
100
|
+
next "last" if number == -1
|
|
101
|
+
suffix = SPECIAL_SUFFIX[number] || NUMBER_SUFFIX[number.abs % 10]
|
|
102
|
+
if number < -1
|
|
103
|
+
number.abs.to_s << suffix << " to last"
|
|
104
|
+
else
|
|
105
|
+
number.to_s << suffix
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
format :daily_interval do |i|
|
|
110
|
+
i == 1 ? "Daily" : "Every #{i} days"
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
format :hourly_interval do |i|
|
|
114
|
+
i == 1 ? "Hourly" : "Every #{i} hours"
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
format :minutely_interval do |i|
|
|
118
|
+
i == 1 ? "Minutely" : "Every #{i} minutes"
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
format :monthly_interval do |i|
|
|
122
|
+
i == 1 ? "Monthly" : "Every #{i} months"
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
format :secondly_interval do |i|
|
|
126
|
+
i == 1 ? "Secondly" : "Every #{i} seconds"
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
format :weekly_interval do |i|
|
|
130
|
+
i == 1 ? "Weekly" : "Every #{i} weeks"
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
format :yearly_interval do |i|
|
|
134
|
+
i == 1 ? "Yearly" : "Every #{i} years"
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
format :exrule do |rule|
|
|
138
|
+
"not #{rule}"
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
format :extime do |time|
|
|
142
|
+
"not on #{build(:time, time)}"
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
format :schedule do |s|
|
|
146
|
+
times = s.recurrence_times_with_start_time - s.extimes
|
|
147
|
+
pieces = []
|
|
148
|
+
pieces.concat times.uniq.sort.map { |t| build(:time, t) }
|
|
149
|
+
pieces.concat s.rrules.map { |t| t.to_s }
|
|
150
|
+
pieces.concat s.exrules.map { |t| build(:exrule, t) }
|
|
151
|
+
pieces.concat s.extimes.uniq.sort.map { |t| build(:extime, t) }
|
|
152
|
+
pieces.join(' / ')
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
module IceCube
|
|
2
|
+
class HashInput
|
|
3
|
+
|
|
4
|
+
class Mash
|
|
5
|
+
def initialize(hash)
|
|
6
|
+
@hash = hash
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
# Fetch values indifferently by symbol or string key without symbolizing
|
|
10
|
+
# arbitrary string input
|
|
11
|
+
#
|
|
12
|
+
def [](key)
|
|
13
|
+
@hash.fetch(key) do |key|
|
|
14
|
+
str_key = key.to_s
|
|
15
|
+
@hash.each_pair.detect do |sym_key, value|
|
|
16
|
+
return value if sym_key.to_s == str_key
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def initialize(hash)
|
|
23
|
+
@input = Mash.new(hash)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def [](key)
|
|
27
|
+
@input[key]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def to_rule
|
|
31
|
+
return nil unless rule_class
|
|
32
|
+
rule = rule_class.new(interval, week_start)
|
|
33
|
+
rule.until(limit_time) if limit_time
|
|
34
|
+
rule.count(limit_count) if limit_count
|
|
35
|
+
validations.each do |validation, args|
|
|
36
|
+
rule.send(validation, *args)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def rule_class
|
|
41
|
+
return @rule_class if @rule_class
|
|
42
|
+
match = @input[:rule_type].match(/::(\w+Rule)$/)
|
|
43
|
+
@rule_class = IceCube.const_get(match[1]) if match
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def interval
|
|
47
|
+
@input[:interval] || 1
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def week_start
|
|
51
|
+
@input[:week_start] || :sunday
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def limit_time
|
|
55
|
+
@limit_time ||= TimeUtil.deserialize_time(@input[:until])
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def limit_count
|
|
59
|
+
@input[:count]
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def validations
|
|
63
|
+
input_validations = Mash.new(@input[:validations] || {})
|
|
64
|
+
ValidatedRule::VALIDATION_ORDER.each_with_object({}) do |key, output_validations|
|
|
65
|
+
args = input_validations[key]
|
|
66
|
+
output_validations[key] = Array(args) if args
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
end
|
|
71
|
+
end
|
data/lib/ice_cube/occurrence.rb
CHANGED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
module IceCube
|
|
2
|
+
class HashParser
|
|
3
|
+
|
|
4
|
+
attr_reader :hash
|
|
5
|
+
|
|
6
|
+
def initialize(original_hash)
|
|
7
|
+
@hash = original_hash
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def to_schedule
|
|
11
|
+
data = normalize_keys(hash)
|
|
12
|
+
schedule = IceCube::Schedule.new parse_time(data[:start_time])
|
|
13
|
+
apply_duration schedule, data
|
|
14
|
+
apply_end_time schedule, data
|
|
15
|
+
apply_rrules schedule, data
|
|
16
|
+
apply_exrules schedule, data
|
|
17
|
+
apply_rtimes schedule, data
|
|
18
|
+
apply_extimes schedule, data
|
|
19
|
+
yield schedule if block_given?
|
|
20
|
+
schedule
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def normalize_keys(hash)
|
|
26
|
+
data = IceCube::FlexibleHash.new(hash.dup)
|
|
27
|
+
|
|
28
|
+
if (start_date = data.delete(:start_date))
|
|
29
|
+
warn "IceCube: :start_date deprecated. (please use :start_time)"
|
|
30
|
+
data[:start_time] = start_date
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
{:rdates => :rtimes, :exdates => :extimes}.each do |old_key, new_key|
|
|
34
|
+
if (times = data.delete(old_key))
|
|
35
|
+
warn "IceCube: :#{old_key} deprecated. (please use :#{new_key})"
|
|
36
|
+
(data[new_key] ||= []).concat times
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
data
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def apply_duration(schedule, data)
|
|
44
|
+
return unless data[:duration]
|
|
45
|
+
schedule.duration = data[:duration].to_i
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def apply_end_time(schedule, data)
|
|
49
|
+
return unless data[:end_time]
|
|
50
|
+
schedule.end_time = parse_time(data[:end_time])
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def apply_rrules(schedule, data)
|
|
54
|
+
return unless data[:rrules]
|
|
55
|
+
data[:rrules].each do |h|
|
|
56
|
+
schedule.rrule(IceCube::Rule.from_hash(h))
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def apply_exrules(schedule, data)
|
|
61
|
+
return unless data[:exrules]
|
|
62
|
+
warn "IceCube: :exrules deprecated. (This will be going away)"
|
|
63
|
+
data[:exrules].each do |h|
|
|
64
|
+
schedule.exrule(IceCube::Rule.from_hash(h))
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def apply_rtimes(schedule, data)
|
|
69
|
+
return unless data[:rtimes]
|
|
70
|
+
data[:rtimes].each do |t|
|
|
71
|
+
schedule.add_recurrence_time TimeUtil.deserialize_time(t)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def apply_extimes(schedule, data)
|
|
76
|
+
return unless data[:extimes]
|
|
77
|
+
data[:extimes].each do |t|
|
|
78
|
+
schedule.add_exception_time TimeUtil.deserialize_time(t)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def parse_time(time)
|
|
83
|
+
TimeUtil.deserialize_time(time)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
end
|
|
87
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module IceCube
|
|
2
|
+
class YamlParser < HashParser
|
|
3
|
+
|
|
4
|
+
SERIALIZED_START = /start_(?:time|date): .+(?<tz>(?:-|\+)\d{2}:\d{2})$/
|
|
5
|
+
|
|
6
|
+
attr_reader :hash
|
|
7
|
+
|
|
8
|
+
def initialize(yaml)
|
|
9
|
+
@hash = YAML::load(yaml)
|
|
10
|
+
yaml.match(SERIALIZED_START) do |match|
|
|
11
|
+
start_time = hash[:start_time] || hash[:start_date]
|
|
12
|
+
hash = FlexibleHash.new(@hash)
|
|
13
|
+
TimeUtil.restore_deserialized_offset start_time, match[:tz]
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
end
|
data/lib/ice_cube/rule.rb
CHANGED
|
@@ -23,24 +23,22 @@ module IceCube
|
|
|
23
23
|
h.nil? ? super : h.hash
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
# Expected to be overridden by subclasses
|
|
27
26
|
def to_ical
|
|
28
|
-
|
|
27
|
+
raise MethodNotImplemented, "Expected to be overrridden by subclasses"
|
|
29
28
|
end
|
|
30
29
|
|
|
31
30
|
# Yaml implementation
|
|
32
31
|
def to_yaml(*args)
|
|
33
|
-
|
|
32
|
+
YAML::dump(to_hash, *args)
|
|
34
33
|
end
|
|
35
34
|
|
|
36
35
|
# From yaml
|
|
37
36
|
def self.from_yaml(yaml)
|
|
38
|
-
from_hash
|
|
37
|
+
from_hash YAML::load(yaml)
|
|
39
38
|
end
|
|
40
39
|
|
|
41
|
-
# Expected to be overridden by subclasses
|
|
42
40
|
def to_hash
|
|
43
|
-
|
|
41
|
+
raise MethodNotImplemented, "Expected to be overridden by subclasses"
|
|
44
42
|
end
|
|
45
43
|
|
|
46
44
|
# Convert from a hash and create a rule
|
|
@@ -72,7 +70,7 @@ module IceCube
|
|
|
72
70
|
|
|
73
71
|
# Whether this rule requires a full run
|
|
74
72
|
def full_required?
|
|
75
|
-
!@count.nil?
|
|
73
|
+
!@count.nil?
|
|
76
74
|
end
|
|
77
75
|
|
|
78
76
|
# Convenience methods for creating Rules
|