recurring_date 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardoc/checksums +3 -0
- data/.yardoc/complete +0 -0
- data/.yardoc/object_types +0 -0
- data/.yardoc/objects/root.dat +0 -0
- data/.yardoc/proxy_types +0 -0
- data/Gemfile.lock +1 -1
- data/README.md +2 -0
- data/doc/Date.html +143 -0
- data/doc/RecurringDate.html +296 -0
- data/doc/RecurringDate/Enumerator.html +2546 -0
- data/doc/_index.html +135 -0
- data/doc/class_list.html +51 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +58 -0
- data/doc/css/style.css +496 -0
- data/doc/file.README.html +144 -0
- data/doc/file_list.html +56 -0
- data/doc/frames.html +17 -0
- data/doc/index.html +144 -0
- data/doc/js/app.js +314 -0
- data/doc/js/full_list.js +216 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +275 -0
- data/doc/top-level-namespace.html +112 -0
- data/lib/recurring_date.rb +3 -0
- data/lib/recurring_date/enumerator.rb +81 -2
- data/lib/recurring_date/version.rb +1 -1
- metadata +24 -2
@@ -0,0 +1,112 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
Top Level Namespace
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.24
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" />
|
16
|
+
|
17
|
+
<script type="text/javascript">
|
18
|
+
pathId = "";
|
19
|
+
relpath = '';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="class_list.html?1"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="_index.html">Index</a> »
|
40
|
+
|
41
|
+
|
42
|
+
<span class="title">Top Level Namespace</span>
|
43
|
+
|
44
|
+
</div>
|
45
|
+
|
46
|
+
<div id="search">
|
47
|
+
|
48
|
+
<a class="full_list_link" id="class_list_link"
|
49
|
+
href="class_list.html">
|
50
|
+
|
51
|
+
<svg width="24" height="24">
|
52
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
54
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
55
|
+
</svg>
|
56
|
+
</a>
|
57
|
+
|
58
|
+
</div>
|
59
|
+
<div class="clear"></div>
|
60
|
+
</div>
|
61
|
+
|
62
|
+
<div id="content"><h1>Top Level Namespace
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
</h1>
|
67
|
+
<div class="box_info">
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
</div>
|
80
|
+
|
81
|
+
<h2>Defined Under Namespace</h2>
|
82
|
+
<p class="children">
|
83
|
+
|
84
|
+
|
85
|
+
<strong class="modules">Modules:</strong> <span class='object_link'><a href="RecurringDate.html" title="RecurringDate (module)">RecurringDate</a></span>
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
<strong class="classes">Classes:</strong> <span class='object_link'><a href="Date.html" title="Date (class)">Date</a></span>
|
90
|
+
|
91
|
+
|
92
|
+
</p>
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
</div>
|
103
|
+
|
104
|
+
<div id="footer">
|
105
|
+
Generated on Tue Mar 24 07:23:15 2020 by
|
106
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
107
|
+
0.9.24 (ruby-2.6.5).
|
108
|
+
</div>
|
109
|
+
|
110
|
+
</div>
|
111
|
+
</body>
|
112
|
+
</html>
|
data/lib/recurring_date.rb
CHANGED
@@ -2,11 +2,14 @@
|
|
2
2
|
|
3
3
|
require 'recurring_date/enumerator'
|
4
4
|
|
5
|
+
# The RecurringDate module is extension to Date class.
|
5
6
|
module RecurringDate
|
7
|
+
# The week number of the month.
|
6
8
|
def mweek
|
7
9
|
(mday - 1) / 7 + 1
|
8
10
|
end
|
9
11
|
|
12
|
+
# Initiate a lazy, perpetual enumerator over all dates, day by day, after +self+ (including +self+).
|
10
13
|
def to_enum
|
11
14
|
RecurringDate::Enumerator.from(self)
|
12
15
|
end
|
@@ -3,7 +3,9 @@
|
|
3
3
|
require 'date'
|
4
4
|
|
5
5
|
module RecurringDate
|
6
|
+
# The enumerator over the dates.
|
6
7
|
class Enumerator < ::Enumerator
|
8
|
+
# Initiate the enumerator.
|
7
9
|
def initialize(range)
|
8
10
|
super() do |result|
|
9
11
|
range.each { |val| block_given? ? yield(result, val) : result << val }
|
@@ -12,80 +14,144 @@ module RecurringDate
|
|
12
14
|
end
|
13
15
|
end
|
14
16
|
|
17
|
+
# Returns a lazy, perpetual enumerator over dates, day by day, from 1st January 1970.
|
15
18
|
def self.eternity
|
16
19
|
from(Date.new(1970))
|
17
20
|
end
|
18
21
|
|
22
|
+
# Returns a lazy, perpetual enumerator over dates, day by day, from +date+.
|
23
|
+
# @param date [Date]
|
19
24
|
def self.from(date)
|
25
|
+
raise ::ArgumentError, 'not a date' unless date.is_a?(::Date)
|
26
|
+
|
20
27
|
RecurringDate::Enumerator.new(infinity(date))
|
21
28
|
end
|
22
29
|
|
30
|
+
# Filter dates by a +yday+ of a date.
|
31
|
+
# @param args [Array] +yday+s
|
23
32
|
def yday(*args)
|
33
|
+
raise ::ArgumentError, 'not an integer' unless args.all? { |arg| arg.is_a?(::Integer) }
|
34
|
+
|
24
35
|
matching(*args, &:yday)
|
25
36
|
end
|
26
37
|
|
38
|
+
# Filter dates by a +mday+ of a date.
|
39
|
+
# @param args [Array] +mday+s
|
27
40
|
def mday(*args)
|
41
|
+
raise ::ArgumentError, 'not an integer' unless args.all? { |arg| arg.is_a?(::Integer) }
|
42
|
+
|
28
43
|
matching(*args, &:mday)
|
29
44
|
end
|
30
45
|
|
46
|
+
# Filter dates by a +wday+ of a date.
|
47
|
+
# @param args [Array] +wday+s
|
31
48
|
def wday(*args)
|
49
|
+
raise ::ArgumentError, 'not an integer' unless args.all? { |arg| arg.is_a?(::Integer) }
|
50
|
+
|
32
51
|
matching(*args, &:wday)
|
33
52
|
end
|
34
53
|
|
54
|
+
# Filter dates by a +mweek+ of a date.
|
55
|
+
# @param args [Array] +mweek+s
|
35
56
|
def mweek(*args)
|
57
|
+
raise ::ArgumentError, 'not an integer' unless args.all? { |arg| arg.is_a?(::Integer) }
|
58
|
+
|
36
59
|
matching(*args, &:mweek)
|
37
60
|
end
|
38
61
|
|
62
|
+
# Filter dates by a +month+ of a date.
|
63
|
+
# @param args [Array] +month+s
|
39
64
|
def month(*args)
|
65
|
+
raise ::ArgumentError, 'not an integer' unless args.all? { |arg| arg.is_a?(::Integer) }
|
66
|
+
|
40
67
|
matching(*args, &:month)
|
41
68
|
end
|
42
69
|
|
70
|
+
# Filter dates by a +year+ of a date.
|
71
|
+
# @param args [Array] +year+s
|
43
72
|
def year(*args)
|
73
|
+
raise ::ArgumentError, 'not an integer' unless args.all? { |arg| arg.is_a?(::Integer) }
|
74
|
+
|
44
75
|
matching(*args, &:year)
|
45
76
|
end
|
46
77
|
|
78
|
+
# Filter dates not maching +yday+.
|
79
|
+
# @param args [Array] +yday+s
|
47
80
|
def not_yday(*args)
|
81
|
+
raise ::ArgumentError, 'not an integer' unless args.all? { |arg| arg.is_a?(::Integer) }
|
82
|
+
|
48
83
|
not_matching(*args, &:yday)
|
49
84
|
end
|
50
85
|
|
86
|
+
# Filter dates not maching +mday+.
|
87
|
+
# @param args [Array] +mday+s
|
51
88
|
def not_mday(*args)
|
89
|
+
raise ::ArgumentError, 'not an integer' unless args.all? { |arg| arg.is_a?(::Integer) }
|
90
|
+
|
52
91
|
not_matching(*args, &:mday)
|
53
92
|
end
|
54
93
|
|
94
|
+
# Filter dates not maching +wday+.
|
95
|
+
# @param args [Array] +wday+s
|
55
96
|
def not_wday(*args)
|
97
|
+
raise ::ArgumentError, 'not an integer' unless args.all? { |arg| arg.is_a?(::Integer) }
|
98
|
+
|
56
99
|
not_matching(*args, &:wday)
|
57
100
|
end
|
58
101
|
|
102
|
+
# Filter dates not maching +mweek+.
|
103
|
+
# @param args [Array] +mweek+s
|
59
104
|
def not_mweek(*args)
|
105
|
+
raise ::ArgumentError, 'not an integer' unless args.all? { |arg| arg.is_a?(::Integer) }
|
106
|
+
|
60
107
|
not_matching(*args, &:mweek)
|
61
108
|
end
|
62
109
|
|
110
|
+
# Filter dates not maching +month+.
|
111
|
+
# @param args [Array] +month+s
|
63
112
|
def not_month(*args)
|
113
|
+
raise ::ArgumentError, 'not an integer' unless args.all? { |arg| arg.is_a?(::Integer) }
|
114
|
+
|
64
115
|
not_matching(*args, &:month)
|
65
116
|
end
|
66
117
|
|
118
|
+
# Filter dates not maching +year+.
|
119
|
+
# @param args [Array] +year+s
|
67
120
|
def not_year(*args)
|
121
|
+
raise ::ArgumentError, 'not an integer' unless args.all? { |arg| arg.is_a?(::Integer) }
|
122
|
+
|
68
123
|
not_matching(*args, &:year)
|
69
124
|
end
|
70
125
|
|
126
|
+
# Filter dates that matches +args+ with yielded block.
|
127
|
+
# @param args [Array] arguments that are compared to the expession in given block.
|
71
128
|
def matching(*args)
|
72
129
|
select { |date| args.include?(yield(date)) }
|
73
130
|
end
|
74
131
|
|
132
|
+
# Filter dates that do not match +args+ with yielded block.
|
133
|
+
# @param args [Array] arguments that are compared to the expession in given block.
|
75
134
|
def not_matching(*args)
|
76
135
|
reject { |date| args.include?(yield(date)) }
|
77
136
|
end
|
78
137
|
|
138
|
+
# Filter dates by the sequence of occurences.
|
139
|
+
# @param args [Array] occurence schema
|
79
140
|
def pattern(*args)
|
80
141
|
select_with_index do |_, i|
|
81
142
|
args.any? { |arg| ((i + 1) % arg).zero? }
|
82
143
|
end
|
83
144
|
end
|
84
145
|
|
85
|
-
|
86
|
-
|
146
|
+
# Set upper bound of the date range (make the enumerator finite).
|
147
|
+
# @param date [Date]
|
148
|
+
def until(date)
|
149
|
+
raise ::ArgumentError, 'not a date' unless date.is_a?(::Date)
|
150
|
+
|
151
|
+
take_while { |obj| obj <= date }
|
87
152
|
end
|
88
153
|
|
154
|
+
# Filter dates by condition in given block. Yields a date and its index.
|
89
155
|
def select_with_index
|
90
156
|
index = 0
|
91
157
|
RecurringDate::Enumerator.new(self) do |result, value|
|
@@ -94,15 +160,21 @@ module RecurringDate
|
|
94
160
|
end
|
95
161
|
end
|
96
162
|
|
163
|
+
# Filter dates by condition in given block.
|
97
164
|
def select
|
98
165
|
RecurringDate::Enumerator.new(self) { |result, value| result << value if yield(value) }
|
99
166
|
end
|
100
167
|
|
168
|
+
# Filter dates by condition in given block. Opposite to +select+.
|
101
169
|
def reject
|
102
170
|
RecurringDate::Enumerator.new(self) { |result, value| result << value unless yield(value) }
|
103
171
|
end
|
104
172
|
|
173
|
+
# Take only +number+ of dates.
|
174
|
+
# @param number [Integer]
|
105
175
|
def take(number)
|
176
|
+
raise ::ArgumentError, 'not an integer' unless number.is_a?(::Integer)
|
177
|
+
|
106
178
|
taken = number
|
107
179
|
RecurringDate::Enumerator.new(self) do |result, value|
|
108
180
|
raise ::StopIteration if taken.zero?
|
@@ -112,6 +184,7 @@ module RecurringDate
|
|
112
184
|
end
|
113
185
|
end
|
114
186
|
|
187
|
+
# Take only dates until the expression in given block has been met.
|
115
188
|
def take_while
|
116
189
|
RecurringDate::Enumerator.new(self) do |result, value|
|
117
190
|
raise ::StopIteration unless yield(value)
|
@@ -120,11 +193,17 @@ module RecurringDate
|
|
120
193
|
end
|
121
194
|
end
|
122
195
|
|
196
|
+
# Dummy inspect for enumerator.
|
123
197
|
def inspect
|
124
198
|
['#<RecurringDate::Enumerator:0x', object_id, '>'].join
|
125
199
|
end
|
126
200
|
|
201
|
+
# The actual enumerator.
|
202
|
+
# The +infinity+ method returns an Enumerator that iterates over a dates, day by day, starting from +date+.
|
203
|
+
# @param date [Date] starting date
|
127
204
|
def self.infinity(date)
|
205
|
+
raise ::ArgumentError, 'not a date' unless date.is_a?(::Date)
|
206
|
+
|
128
207
|
::Enumerator.new do |y|
|
129
208
|
i = date.prev_day
|
130
209
|
loop { y << (i = i.next) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: recurring_date
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paweł Placzyński
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-03-
|
11
|
+
date: 2020-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,6 +94,11 @@ files:
|
|
94
94
|
- ".ruby-gemset"
|
95
95
|
- ".ruby-version"
|
96
96
|
- ".travis.yml"
|
97
|
+
- ".yardoc/checksums"
|
98
|
+
- ".yardoc/complete"
|
99
|
+
- ".yardoc/object_types"
|
100
|
+
- ".yardoc/objects/root.dat"
|
101
|
+
- ".yardoc/proxy_types"
|
97
102
|
- Gemfile
|
98
103
|
- Gemfile.lock
|
99
104
|
- LICENSE
|
@@ -101,6 +106,23 @@ files:
|
|
101
106
|
- Rakefile
|
102
107
|
- bin/console
|
103
108
|
- bin/setup
|
109
|
+
- doc/Date.html
|
110
|
+
- doc/RecurringDate.html
|
111
|
+
- doc/RecurringDate/Enumerator.html
|
112
|
+
- doc/_index.html
|
113
|
+
- doc/class_list.html
|
114
|
+
- doc/css/common.css
|
115
|
+
- doc/css/full_list.css
|
116
|
+
- doc/css/style.css
|
117
|
+
- doc/file.README.html
|
118
|
+
- doc/file_list.html
|
119
|
+
- doc/frames.html
|
120
|
+
- doc/index.html
|
121
|
+
- doc/js/app.js
|
122
|
+
- doc/js/full_list.js
|
123
|
+
- doc/js/jquery.js
|
124
|
+
- doc/method_list.html
|
125
|
+
- doc/top-level-namespace.html
|
104
126
|
- lib/recurring_date.rb
|
105
127
|
- lib/recurring_date/enumerator.rb
|
106
128
|
- lib/recurring_date/version.rb
|