sixarm_ruby_week 1.1.8 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 43c2bf247a81648d563528f841600bfce4b615c0
4
- data.tar.gz: b8c6242e092844a4ba41d2dbacece6b8a2e36954
3
+ metadata.gz: 6db74a3428b9b9ed56a05421475ee480c6c1255b
4
+ data.tar.gz: 4851889f70cfdabc6aab495f1ae3bf8ed93b0730
5
5
  SHA512:
6
- metadata.gz: e9eced63ee4ac973570d7e4c44e460a57a1480cc845e6faf8753e3aa8091ff131c8e7bfaa1a522ab81564a4305e5d2a46183c0607fc0d728e8edfe440cbe6d39
7
- data.tar.gz: c77d05a7d6edc1400ecf4ae1def478bb9c4759e8085c333909a72d0617bbf17a98621e5e0fc2a30067a357c48ba0f90aa57f43497f26c98e4d0d2ba4eaf34b88
6
+ metadata.gz: e319af65dc9fad712d7f12a41d3818329e92c59420e5494299167d993b7f068b3e2736ae6953398dc9b24bdc52628fcc662b3865d6d48eb462c748542deae6dd
7
+ data.tar.gz: 47d14753e907060beab0089de0383fc449d27fd9645381b6ac2e7e5906ac2be872c35403a59d9d8b03e11c9e3490c02d12cc2c5dad66f5c822dd1b3385c6fb8d
Binary file
data.tar.gz.sig CHANGED
Binary file
data/Rakefile CHANGED
@@ -9,4 +9,3 @@ end
9
9
 
10
10
  task :default => [:test]
11
11
  task :default => [:test]
12
- task :default => [:test]
@@ -3,4 +3,4 @@
3
3
  Please see README
4
4
  =end
5
5
 
6
- require "sixarm_ruby_week/week"
6
+ require_relative "sixarm_ruby_week/week"
@@ -0,0 +1,397 @@
1
+ # -*- coding: utf-8 -*-
2
+ =begin rdoc
3
+ Week class.
4
+ =end
5
+
6
+ require "date"
7
+
8
+ class Week
9
+
10
+ attr :date
11
+
12
+ # Initialize the week with a date.
13
+ #
14
+ # Example:
15
+ #
16
+ # require "date"
17
+ # date = Date.today
18
+ # week = Week.new(date)
19
+ #
20
+ # Return:
21
+ #
22
+ # * [Week] The new week
23
+ #
24
+ def initialize(date)
25
+ @date = date
26
+ end
27
+
28
+ # Return the week's date, coverted to a string.
29
+ #
30
+ # Example:
31
+ #
32
+ # date = Date.parse("2015-12-31")
33
+ # week = Week.new(date)
34
+ # week.to_s #=> "2015-12-31"
35
+ #
36
+ # Return:
37
+ #
38
+ # * [String] The week's date, coverted to a string.
39
+ #
40
+ def to_s
41
+ @date.to_s
42
+ end
43
+
44
+ ###
45
+ #
46
+ # Instantiations
47
+ #
48
+ ###
49
+
50
+ # Return the week that starts today
51
+ #
52
+ # Example:
53
+ #
54
+ # week = Week.now
55
+ #
56
+ def self.now
57
+ Week.new(Date.today)
58
+ end
59
+
60
+ # Parse date text to a week.
61
+ #
62
+ # Example:
63
+ #
64
+ # week = Week.parse("2015-12-31")
65
+ #
66
+ # Return:
67
+ #
68
+ # * [Week] A new week.
69
+ #
70
+ def self.parse(date_text)
71
+ Week.new(Date.parse(date_text))
72
+ end
73
+
74
+ ###
75
+ #
76
+ # Comparable
77
+ #
78
+ ###
79
+
80
+ # Return a hash for object comparison.
81
+ #
82
+ # This is simply the hash of the date, which means
83
+ # that two week objects created with the same date
84
+ # always compare equally.
85
+ #
86
+ # Example:
87
+ #
88
+ # date = Date.today
89
+ # date.hash #=> 1655958911300557206
90
+ # week = Week.new(date)
91
+ # week.hash #=> 1655958911300557206
92
+ #
93
+ # Return:
94
+ #
95
+ # * [Fixnum] The week's date's object hash number.
96
+ #
97
+ def hash
98
+ date.hash
99
+ end
100
+
101
+ # Return week1.date == week2.date
102
+ #
103
+ # Example:
104
+ #
105
+ # a = Week.now
106
+ # b = Week.now
107
+ # a == b #=> true
108
+ #
109
+ # Return:
110
+ #
111
+ # * [true,false]
112
+ #
113
+ def ==(other)
114
+ self.date == other.date
115
+ end
116
+
117
+ # Return week1.date.eql? week2.date
118
+ #
119
+ # Example:
120
+ #
121
+ # a = Week.now
122
+ # b = Week.now
123
+ # a.eql? b #=> true
124
+ #
125
+ # Return:
126
+ #
127
+ # * [true,false]
128
+ #
129
+ alias :eql? :==
130
+
131
+ # Return week1.date <=> week2.date
132
+ #
133
+ # a = Week.now
134
+ # b = Week.now
135
+ # a <=> b #=> 0
136
+ #
137
+ # Return:
138
+ #
139
+ # * [-1,0,1]
140
+ #
141
+ def <=>(other)
142
+ return self.date <=> other.date
143
+ end
144
+
145
+
146
+ # Return week1.date < week2.date
147
+ #
148
+ # Example:
149
+ #
150
+ # a = Week.new(date)
151
+ # b = Week.new(date - 1)
152
+ # a < b #=> true
153
+ #
154
+ # Return:
155
+ #
156
+ # * [true,false]
157
+ #
158
+ def <(other)
159
+ self.date < other.date
160
+ end
161
+
162
+
163
+ # Return week1.date <= week2.date
164
+ #
165
+ # Example:
166
+ #
167
+ # a = Week.new(date)
168
+ # b = Week.new(date - 1)
169
+ # a <= b #=> true
170
+ #
171
+ # Return:
172
+ #
173
+ # * [true,false]
174
+ #
175
+ def <=(other)
176
+ self.date <= other.date
177
+ end
178
+
179
+
180
+ # Return week1.date > week2.date
181
+ #
182
+ # Example:
183
+ #
184
+ # a = Week.new(date)
185
+ # b = Week.new(date + 1)
186
+ # a > b #=> true
187
+ #
188
+ # Return:
189
+ #
190
+ # * [true,false]
191
+ #
192
+ def >(other)
193
+ self.date > other.date
194
+ end
195
+
196
+
197
+ # Return week1.date >= week2.date
198
+ #
199
+ # Example:
200
+ #
201
+ # a = Week.new(date)
202
+ # b = Week.new(date + 1)
203
+ # a >= b #=> true
204
+ #
205
+ # Return:
206
+ #
207
+ # * [true,false]
208
+ #
209
+ def >=(other)
210
+ self.date >= other.date
211
+ end
212
+
213
+ ###
214
+ #
215
+ # Math
216
+ #
217
+ ###
218
+
219
+ # Addition: week + other => week
220
+ #
221
+ # Return a date object pointing at other weeks after self.
222
+ #
223
+ # The other should be a numeric value.
224
+ #
225
+ # Example:
226
+ #
227
+ # week = Week.new(date)
228
+ # week + 3 #=> three weeks later
229
+ #
230
+ # Return:
231
+ #
232
+ # * [Week]
233
+ #
234
+ def +(other)
235
+ if other.is_a? Numeric
236
+ return Week.new(date + (other.to_i * 7))
237
+ else
238
+ raise TypeError
239
+ end
240
+ end
241
+
242
+ # Subtraction: week - other => week or integer
243
+ #
244
+ # If the other is a numeric value, return a week object pointing other weeks before self.
245
+ #
246
+ # If the other is a week object, then return the difference between the two weeks.
247
+ #
248
+ # Example:
249
+ #
250
+ # week = Week.new(date)
251
+ # week - 3 => three weeks earlier
252
+ #
253
+ # Example:
254
+ #
255
+ # a = Week.new(date)
256
+ # b = Week.new(date + 21)
257
+ # b - a => 3
258
+ #
259
+ # Return:
260
+ #
261
+ # * [Week]
262
+ #
263
+ def -(other)
264
+ if other.is_a? Numeric
265
+ return Week.new(date - (other * 7))
266
+ elsif other.is_a? Week
267
+ return ((self.date - other.date) / 7).round
268
+ else
269
+ raise TypeError
270
+ end
271
+ end
272
+
273
+ ###
274
+ #
275
+ # Enumerable
276
+ #
277
+ ###
278
+
279
+ # Return the previous week, i.e. seven days earlier.
280
+ #
281
+ # Example:
282
+ #
283
+ # week = Week.new(date)
284
+ # week.previous #=> seven days earlier
285
+ #
286
+ # Return:
287
+ #
288
+ # * [Week] The previous week
289
+ #
290
+ def previous
291
+ return self - 1
292
+ end
293
+
294
+ # Return the next week, i.e. seven days later.
295
+ #
296
+ # Example:
297
+ #
298
+ # week = Week.new(date)
299
+ # week.next #=> seven days later.
300
+ #
301
+ # Return:
302
+ #
303
+ # * [Week] The next week
304
+ #
305
+ def next
306
+ return self + 1
307
+ end
308
+
309
+ ###
310
+ #
311
+ # Ranges
312
+ #
313
+ ###
314
+
315
+ # Return the first date of this week.
316
+ #
317
+ # Example:
318
+ #
319
+ # week = Week.new(date)
320
+ # week.first_date #=> date
321
+ #
322
+ # Aliases:
323
+ #
324
+ # week.begin_date
325
+ # week.start_date
326
+ #
327
+ ## Return:
328
+ #
329
+ # * [Date] week.date
330
+ #
331
+ def first_date
332
+ @date
333
+ end
334
+
335
+ alias :begin_date :first_date
336
+ alias :start_date :first_date
337
+
338
+ # Return the last date of this week.
339
+ #
340
+ # Return
341
+ #
342
+ # Example:
343
+ #
344
+ # week = Week.new(date)
345
+ # week.last_date #=> date + 6
346
+ #
347
+ # Aliases:
348
+ #
349
+ # week.end_date
350
+ # week.stop_date
351
+ #
352
+ # Return:
353
+ #
354
+ # * [Date] week.date + 6
355
+ #
356
+ def last_date
357
+ @date + 6
358
+ end
359
+
360
+ alias :end_date :last_date
361
+ alias :stop_date :last_date
362
+
363
+ # Return the date range of the week.
364
+ #
365
+ # This returns start_date..end_date.
366
+ #
367
+ # Example:
368
+ #
369
+ # week = Week.now
370
+ # week.date_range => Range(2012-01-02..2012-01-08)
371
+ #
372
+ # Return:
373
+ #
374
+ # * [Range] start_date..stop_date
375
+ #
376
+ def date_range
377
+ start_date..stop_date
378
+ end
379
+
380
+ # Does the week includes the date?
381
+ #
382
+ # Example:
383
+ #
384
+ # date = Date.today
385
+ # week = Week.new(date)
386
+ # week.include?(date + 1) => true
387
+ # week.include?(date + 7) => false
388
+ #
389
+ # Return:
390
+ #
391
+ # * [true/false]
392
+ #
393
+ def include?(date)
394
+ (start_date..end_date).include?(date)
395
+ end
396
+
397
+ end
@@ -8,3 +8,4 @@ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
8
8
  Coveralls::SimpleCov::Formatter
9
9
  ]
10
10
  SimpleCov.start
11
+ require "sixarm_ruby_week"
@@ -1,6 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require "sixarm_ruby_week_test"
3
- require "sixarm_ruby_week/week"
4
3
 
5
4
  describe Week do
6
5
 
@@ -309,53 +308,62 @@ describe Week do
309
308
 
310
309
  end
311
310
 
312
- describe "#start_date" do
311
+ describe "#first_date" do
313
312
 
314
313
  it "=> Date" do
315
- WEEK.start_date.must_be_kind_of Date
314
+ WEEK.first_date.must_be_kind_of Date
316
315
  end
317
316
 
318
317
  it "=> the initialzation date" do
319
- WEEK.start_date.must_equal DATE
318
+ WEEK.first_date.must_equal DATE
320
319
  end
321
320
 
322
- end
323
-
321
+ end
322
+
324
323
  describe "#begin_date" do
325
324
 
326
- it "=> Date" do
327
- WEEK.begin_date.must_be_kind_of Date
325
+ it "alias" do
326
+ WEEK.method(:begin_date) == WEEK.method(:first_date)
328
327
  end
329
328
 
330
- it "=> the initialzation date" do
331
- WEEK.begin_date.must_equal DATE
329
+ end
330
+
331
+ describe "#start_date" do
332
+
333
+ it "alias" do
334
+ WEEK.method(:start_date) == WEEK.method(:first_date)
332
335
  end
333
336
 
334
337
  end
335
-
336
- describe "#stop_date" do
338
+
339
+ describe "#last_date" do
337
340
 
338
341
  it "=> Date" do
339
- WEEK.stop_date.must_be_kind_of Date
342
+ WEEK.last_date.must_be_kind_of Date
340
343
  end
341
344
 
342
345
  it "=> six days after the initialization date" do
343
- WEEK.stop_date.must_equal DATE + 6
346
+ WEEK.last_date.must_equal DATE + 6
344
347
  end
345
348
 
346
349
  end
347
350
 
348
351
  describe "#end_date" do
349
352
 
350
- it "=> Date" do
351
- WEEK.end_date.must_be_kind_of Date
353
+ it "alias" do
354
+ WEEK.method(:end_date) == WEEK.method(:last_date)
352
355
  end
353
356
 
354
- it "=> six days after the initialization date" do
355
- WEEK.end_date.must_equal DATE + 6
357
+ end
358
+
359
+ describe "#stop_date" do
360
+
361
+ it "alias" do
362
+ WEEK.method(:stop_date) == WEEK.method(:last_date)
356
363
  end
357
364
 
358
365
  end
366
+
359
367
 
360
368
  describe "#date_range" do
361
369
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sixarm_ruby_week
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.8
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - SixArm
@@ -44,7 +44,7 @@ cert_chain:
44
44
  2AC9FOGkybW6DJEFSFFMlNk0IILsa/gNp8ufGuTVLWF9FUUdMNK+TMbghnifT8/1
45
45
  n+ES/gQPOnvmVkLDGw==
46
46
  -----END CERTIFICATE-----
47
- date: 2015-07-18 00:00:00.000000000 Z
47
+ date: 2017-08-13 00:00:00.000000000 Z
48
48
  dependencies:
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: minitest
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "<"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sixarm_ruby_minitest_extensions
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 1.0.5
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 1.0.5
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rake
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -134,15 +148,17 @@ extra_rdoc_files: []
134
148
  files:
135
149
  - Rakefile
136
150
  - lib/sixarm_ruby_week.rb
151
+ - lib/sixarm_ruby_week/week.rb
137
152
  - test/sixarm_ruby_week_test.rb
138
153
  - test/sixarm_ruby_week_test/week_test.rb
139
154
  homepage: http://sixarm.com/
140
155
  licenses:
141
- - BSD
142
- - GPL
156
+ - Apache-2.0
157
+ - Artistic-2.0
158
+ - BSD-3-Clause
159
+ - GPL-3.0
143
160
  - MIT
144
- - PAL
145
- - Various
161
+ - MPL-2.0
146
162
  metadata: {}
147
163
  post_install_message:
148
164
  rdoc_options: []
@@ -160,11 +176,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
176
  version: '0'
161
177
  requirements: []
162
178
  rubyforge_project:
163
- rubygems_version: 2.4.8
179
+ rubygems_version: 2.6.12
164
180
  signing_key:
165
181
  specification_version: 4
166
- summary: SixArm.com » Ruby » Week
182
+ summary: SixArm.com Ruby Week
167
183
  test_files:
168
184
  - test/sixarm_ruby_week_test.rb
169
185
  - test/sixarm_ruby_week_test/week_test.rb
170
- has_rdoc: true
metadata.gz.sig CHANGED
Binary file