ice_cube 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -1,5 +1,5 @@
1
1
  module IceCube
2
2
 
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.1"
4
4
 
5
5
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 0
9
- version: 0.3.0
8
+ - 1
9
+ version: 0.3.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - John Crepezzi
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-21 00:00:00 -04:00
17
+ date: 2010-04-26 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency