fat_core 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49d7213a1c1d8f0372f9a5f0e057dec4a194e541
4
- data.tar.gz: 6f8ee1ddc0bfb0e8b66247453e2f4c11fc51d0d1
3
+ metadata.gz: c3022e21efd8b8e152772e4e7c02ef38561f2fdb
4
+ data.tar.gz: f79d325c96f94aa4d961f2315dcc6901533c6b46
5
5
  SHA512:
6
- metadata.gz: 074407a3a3e4b7885d841b8fe351c18fd03d001620058e9364129fe82f995d3e25554c4b3c2bb364851e006faa95778929bc7342d7799ed8d8c10956421fb64f
7
- data.tar.gz: 4d0d70cfc49d8f1152db707a8eb43672d5fcf1586f088e41646a3f33f2d49c2634c15d5944246624a80bc325e277559a960e5e9840077804d4296f2ba1b00d61
6
+ metadata.gz: 431ecd4c693f038bdf70b026a5f9445e45b497f36658180d6f7db12a653a85e7ce55770b7245e3ed5cec064ca185d8318423bc5ce835650cc6d0be2e5dacef4e
7
+ data.tar.gz: a2de458910bda7ffe1841684ffe128cd012455280dc7efcc21c0b3f8c48d9f847b458a68542c1ba5fec7ee3af8f54cdc1038d9496ce3dfa0b1da59f3949e7eef
@@ -216,6 +216,28 @@ class Period
216
216
  end
217
217
  end
218
218
 
219
+ # The smallest number of days possible in each chunk
220
+ def self.chunk_sym_to_min_days(sym)
221
+ case sym
222
+ when :semimonth
223
+ 15
224
+ when :month
225
+ 28
226
+ when :bimonth
227
+ 59
228
+ when :quarter
229
+ 86
230
+ when :half
231
+ 180
232
+ when :year
233
+ 365
234
+ when :irregular
235
+ raise ArgumentError, 'no minimum period for :irregular chunk'
236
+ else
237
+ chunk_sym_to_days(sym)
238
+ end
239
+ end
240
+
219
241
  # The largest number of days possible in each chunk
220
242
  def self.chunk_sym_to_max_days(sym)
221
243
  case sym
@@ -430,15 +452,18 @@ class Period
430
452
  .map { |r| Period.new(r.first, r.last) }
431
453
  end
432
454
 
433
- # Return an array of Periods wholly-contained within self in chunks of
434
- # size, defaulting to monthly chunks. Partial chunks at the beginning and
435
- # end of self are not included unless partial_first or partial_last,
436
- # respectively, are set true. The last chunk can be made to extend beyond
437
- # the end of self to make it a whole chunk if round_up_last is set true,
438
- # in which case, partial_last is ignored.
455
+ # Return an array of Periods wholly-contained within self in chunks of size,
456
+ # defaulting to monthly chunks. Partial chunks at the beginning and end of
457
+ # self are not included unless partial_first or partial_last, respectively,
458
+ # are set true. The last chunk can be made to extend beyond the end of self to
459
+ # make it a whole chunk if round_up_last is set true, in which case,
460
+ # partial_last is ignored.
439
461
  def chunks(size: :month, partial_first: false, partial_last: false,
440
462
  round_up_last: false)
441
463
  size = size.to_sym
464
+ if Period.chunk_sym_to_min_days(size) > length
465
+ raise ArgumentError, "any #{size} is longer than this period's #{length} days"
466
+ end
442
467
  result = []
443
468
  chunk_start = first.dup
444
469
  while chunk_start <= last
@@ -1,7 +1,7 @@
1
1
  module FatCore
2
2
  MAJOR = 1
3
3
  MINOR = 3
4
- PATCH = 0
4
+ PATCH = 1
5
5
 
6
6
  VERSION = [MAJOR, MINOR, PATCH].compact.join('.')
7
7
  end
@@ -455,7 +455,13 @@ describe Period do
455
455
  it 'should raise error for invalid chunk name' do
456
456
  expect {
457
457
  Period.new('2012-12-28', '2012-12-31').chunks(size: :wally)
458
- }.to raise_error(ArgumentError)
458
+ }.to raise_error /unknown chunk sym/
459
+ end
460
+
461
+ it 'should raise error for too large a chunk' do
462
+ expect {
463
+ Period.new('2012-12-01', '2012-12-31').chunks(size: :bimonth)
464
+ }.to raise_error /longer than/
459
465
  end
460
466
 
461
467
  it 'should not include a partial final chunk by default' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fat_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel E. Doherty