repeatable 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -2
- data/lib/repeatable/schedule.rb +12 -4
- data/lib/repeatable/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03a465c906b9b2d7fdff5ffc02f1d101f87d3ab8
|
4
|
+
data.tar.gz: d29495e2f3820d482dc6a7e71c21623db1d8a8bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 857276ebf76281f5aa7b2c71599417aeb1da1e7fc0f5bbda36806f5165b47eb92a10ede29e510351858eb0b32a3c5dbb2e82f485cacecf9e8547e2ec1605ec07
|
7
|
+
data.tar.gz: 4f5cc44ae471c8bf0006c4570c09e829b803f44cb5661c3dc9fce721e1ed519ecc3b5373016b70d9ad6a2952c96b0fc75dfd2f51d27875fdc2ec555ee9d652fd
|
data/README.md
CHANGED
@@ -101,14 +101,32 @@ Repeatable::Expression::RangeInYear.new(start_month: 10, end_month: 12)
|
|
101
101
|
Repeatable::Expression::RangeInYear.new(start_month: 10, end_month: 12, start_day: 1, end_day: 20)
|
102
102
|
```
|
103
103
|
|
104
|
+
#### Schedule Errors
|
105
|
+
|
106
|
+
If something in the argument passed into `Repeatable::Schedule.new` can't be handled by the `Schedule` or `Parser` (e.g. an expression hash key that doesn't match an existing expression class), a `Repeatable::ParseError` will be raised with a (hopefully) helpful error message.
|
107
|
+
|
104
108
|
### Getting information from a Schedule
|
105
109
|
|
106
|
-
Ask a schedule
|
110
|
+
Ask a schedule to do a number of things.
|
107
111
|
|
108
112
|
```ruby
|
109
113
|
schedule.next_occurrence
|
110
114
|
# => Date of next occurrence
|
111
115
|
|
116
|
+
# By default, it will find the next occurrence after Date.today.
|
117
|
+
# You can also specify a start date.
|
118
|
+
schedule.next_occurrence(Date.new(2015, 1, 1))
|
119
|
+
# => Date of next occurrence after Jan 1, 2015
|
120
|
+
|
121
|
+
# You also have the option of including the start date as a possible result.
|
122
|
+
schedule.next_occurrence(Date.new(2015, 1, 1), include_start: true)
|
123
|
+
# => Date of next occurrence on or after Jan 1, 2015
|
124
|
+
|
125
|
+
# By default, searches for the next occurrence are limited to the next 36,525 days (about 100 years).
|
126
|
+
# That limit can also be specified in number of days.
|
127
|
+
schedule.next_occurrence(limit: 365)
|
128
|
+
# => Date of next occurrence within the next 365 days
|
129
|
+
|
112
130
|
schedule.occurrences(Date.new(2015, 1, 1), Date.new(2016, 6, 30))
|
113
131
|
# => Dates of all occurrences between Jan 1, 2015 and June 30, 2016
|
114
132
|
|
@@ -117,7 +135,7 @@ schedule.include?(Date.new(2015, 10, 10))
|
|
117
135
|
|
118
136
|
schedule.to_h
|
119
137
|
# => Hash representation of the Schedule, which is useful for storage and
|
120
|
-
# can be used to
|
138
|
+
# can be used to recreate an identical Schedule object at a later time
|
121
139
|
```
|
122
140
|
|
123
141
|
## Development
|
data/lib/repeatable/schedule.rb
CHANGED
@@ -9,22 +9,30 @@ module Repeatable
|
|
9
9
|
when Hash
|
10
10
|
@expression = Parser.call(arg)
|
11
11
|
else
|
12
|
-
fail(
|
12
|
+
fail(ParseError, "Can't build a Repeatable::Schedule from #{arg.class}")
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
def occurrences(start_date, end_date)
|
17
17
|
start_date = Date(start_date)
|
18
18
|
end_date = Date(end_date)
|
19
|
+
|
20
|
+
fail(ArgumentError, 'end_date must be equal to or after start_date') if end_date < start_date
|
21
|
+
|
19
22
|
(start_date..end_date).select { |date| include?(date) }
|
20
23
|
end
|
21
24
|
|
22
|
-
def next_occurrence(start_date = Date.today)
|
25
|
+
def next_occurrence(start_date = Date.today, include_start: false, limit: 36525)
|
23
26
|
date = Date(start_date)
|
24
|
-
|
27
|
+
|
28
|
+
return date if include_start && include?(date)
|
29
|
+
|
30
|
+
1.step do |i|
|
25
31
|
date = date.next_day
|
32
|
+
|
33
|
+
break date if include?(date)
|
34
|
+
break if i == limit.to_i
|
26
35
|
end
|
27
|
-
date
|
28
36
|
end
|
29
37
|
|
30
38
|
def include?(date = Date.today)
|
data/lib/repeatable/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: repeatable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mo Lawson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|