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 +4 -4
- data/lib/fat_core/period.rb +31 -6
- data/lib/fat_core/version.rb +1 -1
- data/spec/lib/period_spec.rb +7 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3022e21efd8b8e152772e4e7c02ef38561f2fdb
|
4
|
+
data.tar.gz: f79d325c96f94aa4d961f2315dcc6901533c6b46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 431ecd4c693f038bdf70b026a5f9445e45b497f36658180d6f7db12a653a85e7ce55770b7245e3ed5cec064ca185d8318423bc5ce835650cc6d0be2e5dacef4e
|
7
|
+
data.tar.gz: a2de458910bda7ffe1841684ffe128cd012455280dc7efcc21c0b3f8c48d9f847b458a68542c1ba5fec7ee3af8f54cdc1038d9496ce3dfa0b1da59f3949e7eef
|
data/lib/fat_core/period.rb
CHANGED
@@ -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
|
-
#
|
435
|
-
#
|
436
|
-
#
|
437
|
-
#
|
438
|
-
#
|
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
|
data/lib/fat_core/version.rb
CHANGED
data/spec/lib/period_spec.rb
CHANGED
@@ -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
|
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
|