date_range_covers 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -22,13 +22,13 @@ Or install it yourself as:
22
22
 
23
23
  start_date = Date.parse('2013-01-01')
24
24
  end_date = Date.parse('2013-04-11')
25
- start_of_week = :sunday
25
+ start_of_week = :sunday #or :monday
26
26
 
27
27
  d = DateRangeCovers::DateRange.new(start_date, end_date, start_of_week)
28
28
 
29
- d.covers
29
+ d.covers #the date range partitioned into months, weeks and days
30
30
  => {
31
- :dates=>[
31
+ :days=>[
32
32
  Mon, 01 Apr 2013, Tue, 02 Apr 2013, Wed, 03 Apr 2013, Thu, 04 Apr 2013,
33
33
  Fri, 05 Apr 2013, Sat, 06 Apr 2013, Sun, 07 Apr 2013, Mon, 08 Apr 2013,
34
34
  Tue, 09 Apr 2013, Wed, 10 Apr 2013, Thu, 11 Apr 2013
@@ -37,6 +37,25 @@ Or install it yourself as:
37
37
  :weeks=>[]
38
38
  }
39
39
 
40
+ params = [:days] #all dates within the date range
41
+ d.covers params
42
+
43
+ params = [:weeks] #the days in the date range partitioned into weeks/days
44
+ d.covers params
45
+
46
+ params = [:months] #days in the date range partitioned into months/days
47
+ d.covers params
48
+
49
+ params = [:days, :weeks] #same as [:weeks]
50
+ d.covers params
51
+
52
+ params = [:days, :months] #same as [:months]
53
+ d.covers params
54
+
55
+ params = [:weeks, :months] #same as [:all]
56
+ d.covers params
57
+
58
+
40
59
  ## Contributing
41
60
 
42
61
  1. Fork it
@@ -201,7 +201,7 @@ module DateRangeCovers
201
201
  dates = handle_date_range(s_date, e_date, options)
202
202
  end
203
203
 
204
- covs[:dates] = dates.compact.sort
204
+ covs[:days] = dates.compact.sort
205
205
  end
206
206
 
207
207
  def handle_single_date_range(s_date, e_date, options)
@@ -231,6 +231,28 @@ module DateRangeCovers
231
231
  return (s_date..e_date).collect { |date| date unless is_covered?(date) }
232
232
  end
233
233
 
234
+ # Returns dates within a date range, partitioned in
235
+ # months/weeks/days.
236
+ #
237
+ # Dates that are not boxed by a week or month, are returned as days.
238
+ #
239
+ # @example
240
+ # covered_range = DateRangeCovers::DateRange.covers
241
+ # covered_range = DateRangeCovers::DateRange.covers(params)
242
+ #
243
+ # @params
244
+ # [:all] or no params => default, the date range partitioned into months, weeks and days
245
+ # [:days] => all dates within the date range
246
+ # [:weeks] => the days in the date range partitioned into weeks/days
247
+ # [:months] => days in the date range partitioned into months/days
248
+
249
+ # [:days, :weeks] => same as [:weeks]
250
+ # [:days, :months] => same as [:months]
251
+ # [:weeks, :months] => same as [:all]
252
+ #
253
+ # @return Hash
254
+ #
255
+ # @api public
234
256
  def covers(cover_options = [:all])
235
257
  @covs = {}
236
258
 
@@ -1,3 +1,3 @@
1
1
  module DateRangeCovers
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -311,9 +311,9 @@ describe DateRangeCovers do
311
311
  covers[:weeks].should include Date.parse(date)
312
312
  end
313
313
 
314
- covers[:dates].length.should == 6
314
+ covers[:days].length.should == 6
315
315
  %w(2013-03-06 2013-03-07 2013-03-08 2013-03-09 2013-03-31 2013-06-01).each do |date|
316
- covers[:dates].should include Date.parse(date)
316
+ covers[:days].should include Date.parse(date)
317
317
  end
318
318
  end
319
319
  end
@@ -328,12 +328,12 @@ describe DateRangeCovers do
328
328
 
329
329
  covers[:weeks].should be_nil
330
330
 
331
- covers[:dates].length.should == 48
331
+ covers[:days].length.should == 48
332
332
  (6..31).each do |day|
333
- covers[:dates].should include Date.parse("2013-03-#{day}")
333
+ covers[:days].should include Date.parse("2013-03-#{day}")
334
334
  end
335
335
  (1..22).each do |day|
336
- covers[:dates].should include Date.parse("2013-06-#{day}")
336
+ covers[:days].should include Date.parse("2013-06-#{day}")
337
337
  end
338
338
  end
339
339
  end
@@ -343,18 +343,18 @@ describe DateRangeCovers do
343
343
  it "should return with just the weeks and dates" do
344
344
  covers[:months].should be_nil
345
345
  covers[:weeks].length.should == 15
346
- covers[:dates].length.should == 4
346
+ covers[:days].length.should == 4
347
347
  end
348
348
  end
349
349
 
350
350
  context 'when include is :dates' do
351
- let(:covers) { drange.covers([:dates]) }
351
+ let(:covers) { drange.covers([:days]) }
352
352
  it "should return with just the days between" do
353
353
  covers[:months].should be_nil
354
354
  covers[:weeks].should be_nil
355
- covers[:dates].length.should == (start_date..end_date).collect {|date| date}.length
355
+ covers[:days].length.should == (start_date..end_date).collect {|date| date}.length
356
356
  (start_date..end_date).each do |date|
357
- covers[:dates].should include date
357
+ covers[:days].should include date
358
358
  end
359
359
  end
360
360
  end
@@ -371,12 +371,12 @@ describe DateRangeCovers do
371
371
  covers[:months].should be_empty
372
372
  covers[:weeks].length.should == 1
373
373
  covers[:weeks].should include Date.parse('2013-03-10')
374
- covers[:dates].length.should == 10
374
+ covers[:days].length.should == 10
375
375
  (Date.parse('2013-03-06')..Date.parse('2013-03-09')).each do |date|
376
- covers[:dates].should include date
376
+ covers[:days].should include date
377
377
  end
378
378
  (Date.parse('2013-03-17')..Date.parse('2013-03-22')).each do |date|
379
- covers[:dates].should include date
379
+ covers[:days].should include date
380
380
  end
381
381
  end
382
382
  end
@@ -386,9 +386,9 @@ describe DateRangeCovers do
386
386
  it "should return with just the days between" do
387
387
  covers[:months].should be_empty
388
388
  covers[:weeks].should be_nil
389
- covers[:dates].length.should == 17
389
+ covers[:days].length.should == 17
390
390
  (start_date..end_date).each do |date|
391
- covers[:dates].should include date
391
+ covers[:days].should include date
392
392
  end
393
393
  end
394
394
  end
@@ -399,24 +399,24 @@ describe DateRangeCovers do
399
399
  covers[:months].should be_nil
400
400
  covers[:weeks].length.should == 1
401
401
  covers[:weeks].should include Date.parse('2013-03-10')
402
- covers[:dates].length.should == 10
402
+ covers[:days].length.should == 10
403
403
  (Date.parse('2013-03-06')..Date.parse('2013-03-09')).each do |date|
404
- covers[:dates].should include date
404
+ covers[:days].should include date
405
405
  end
406
406
  (Date.parse('2013-03-17')..Date.parse('2013-03-22')).each do |date|
407
- covers[:dates].should include date
407
+ covers[:days].should include date
408
408
  end
409
409
  end
410
410
  end
411
411
 
412
412
  context 'when include is :dates' do
413
- let(:covers) { drange.covers([:dates]) }
413
+ let(:covers) { drange.covers([:days]) }
414
414
  it "should return with just the days between" do
415
415
  covers[:months].should be_nil
416
416
  covers[:weeks].should be_nil
417
- covers[:dates].length.should == 17
417
+ covers[:days].length.should == 17
418
418
  (start_date..end_date).each do |date|
419
- covers[:dates].should include date
419
+ covers[:days].should include date
420
420
  end
421
421
  end
422
422
  end
@@ -432,9 +432,9 @@ describe DateRangeCovers do
432
432
  it "should return with just the days between" do
433
433
  covers[:months].should be_empty
434
434
  covers[:weeks].should be_empty
435
- covers[:dates].should_not be_empty
435
+ covers[:days].should_not be_empty
436
436
  (start_date..end_date).each do |date|
437
- covers[:dates].should include date
437
+ covers[:days].should include date
438
438
  end
439
439
  end
440
440
  end
@@ -444,9 +444,9 @@ describe DateRangeCovers do
444
444
  it "should return with just the days between" do
445
445
  covers[:months].should be_empty
446
446
  covers[:weeks].should be_nil
447
- covers[:dates].should_not be_empty
447
+ covers[:days].should_not be_empty
448
448
  (start_date..end_date).each do |date|
449
- covers[:dates].should include date
449
+ covers[:days].should include date
450
450
  end
451
451
  end
452
452
  end
@@ -456,21 +456,21 @@ describe DateRangeCovers do
456
456
  it "should return with just the days between" do
457
457
  covers[:months].should be_nil
458
458
  covers[:weeks].should be_empty
459
- covers[:dates].should_not be_empty
459
+ covers[:days].should_not be_empty
460
460
  (start_date..end_date).each do |date|
461
- covers[:dates].should include date
461
+ covers[:days].should include date
462
462
  end
463
463
  end
464
464
  end
465
465
 
466
466
  context 'when include is :dates' do
467
- let(:covers) { drange.covers([:dates]) }
467
+ let(:covers) { drange.covers([:days]) }
468
468
  it "should return with just the days between" do
469
469
  covers[:months].should be_nil
470
470
  covers[:weeks].should be_nil
471
- covers[:dates].should_not be_empty
471
+ covers[:days].should_not be_empty
472
472
  (start_date..end_date).each do |date|
473
- covers[:dates].should include date
473
+ covers[:days].should include date
474
474
  end
475
475
  end
476
476
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: date_range_covers
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Antall Fernandes
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-03-20 00:00:00 Z
18
+ date: 2013-03-25 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: bundler