ice_cube 0.3 → 0.3.1
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.
- data/lib/ice_cube/schedule.rb +12 -6
- data/lib/ice_cube/version.rb +1 -1
- metadata +3 -2
data/lib/ice_cube/schedule.rb
CHANGED
@@ -12,6 +12,7 @@ module IceCube
|
|
12
12
|
@start_date = start_date
|
13
13
|
end
|
14
14
|
|
15
|
+
# Convert the schedule to a hash, reverse of Schedule.from_hash
|
15
16
|
def to_hash
|
16
17
|
hash = Hash.new
|
17
18
|
hash[:start_date] = @start_date
|
@@ -21,11 +22,13 @@ module IceCube
|
|
21
22
|
hash[:exdates] = @exdates
|
22
23
|
hash
|
23
24
|
end
|
24
|
-
|
25
|
+
|
26
|
+
# Convert the schedule to yaml, reverse of Schedule.from_yaml
|
25
27
|
def to_yaml
|
26
28
|
to_hash.to_yaml
|
27
29
|
end
|
28
|
-
|
30
|
+
|
31
|
+
# Create a schedule from a hash created by instance.to_hash
|
29
32
|
def self.from_hash(hash)
|
30
33
|
schedule = Schedule.new(hash[:start_date])
|
31
34
|
hash[:rrules].each { |rr| schedule.add_recurrence_rule Rule.from_hash(rr) }
|
@@ -34,7 +37,8 @@ module IceCube
|
|
34
37
|
hash[:exdates].each { |ed| schedule.add_exception_date ed }
|
35
38
|
schedule
|
36
39
|
end
|
37
|
-
|
40
|
+
|
41
|
+
# Create a schedule from a yaml string created by instance.to_yaml
|
38
42
|
def self.from_yaml(str)
|
39
43
|
from_hash(YAML::load(str))
|
40
44
|
end
|
@@ -63,7 +67,9 @@ module IceCube
|
|
63
67
|
def occurrences(end_date)
|
64
68
|
find_occurrences { |head| head.upto(end_date) }
|
65
69
|
end
|
66
|
-
|
70
|
+
|
71
|
+
# Retrieve the first (n) occurrences of the schedule. May return less than
|
72
|
+
# n results, if the rules end before n results are reached.
|
67
73
|
def first(n)
|
68
74
|
dates = find_occurrences { |head| head.first(n) }
|
69
75
|
dates.slice(0, n)
|
@@ -91,12 +97,12 @@ module IceCube
|
|
91
97
|
|
92
98
|
# Add an individual date to this schedule
|
93
99
|
def add_recurrence_date(date)
|
94
|
-
@rdates << date
|
100
|
+
@rdates << date unless date.nil?
|
95
101
|
end
|
96
102
|
|
97
103
|
# Add an individual date exception to this schedule
|
98
104
|
def add_exception_date(date)
|
99
|
-
@exdates << date
|
105
|
+
@exdates << date unless date.nil?
|
100
106
|
end
|
101
107
|
|
102
108
|
attr_reader :rdates, :exdates
|
data/lib/ice_cube/version.rb
CHANGED
metadata
CHANGED
@@ -5,7 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
|
8
|
+
- 1
|
9
|
+
version: 0.3.1
|
9
10
|
platform: ruby
|
10
11
|
authors:
|
11
12
|
- John Crepezzi
|
@@ -13,7 +14,7 @@ autorequire:
|
|
13
14
|
bindir: bin
|
14
15
|
cert_chain: []
|
15
16
|
|
16
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-26 00:00:00 -04:00
|
17
18
|
default_executable:
|
18
19
|
dependencies:
|
19
20
|
- !ruby/object:Gem::Dependency
|