fat_core 1.0.2 → 1.0.3
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 +8 -6
- data/lib/fat_core/version.rb +1 -1
- data/spec/lib/period_spec.rb +21 -2
- 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: b32e345632ac5b6bccac049d806eed45e6a2074b
|
4
|
+
data.tar.gz: e585990b0c1b6102e0d96f010107a5ec79b093a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d57d6d4df7e207a6aec6801ce6af4dff27b696a9e1fa76d301b1d550c7904fa95bc6cd5e275f39ff9e9455d242c965bd6bbf5d04d31414a9f2f67ae4eb9fca9a
|
7
|
+
data.tar.gz: 804231e68d96590a6a898eb0de9e1fd206f1f8e1fbdaa95b59904f25702e971e8db6ba510f02fad2a4116e8e1cac94171dcd0f3f970077cdc4c222daca8a20e0
|
data/lib/fat_core/period.rb
CHANGED
@@ -186,7 +186,7 @@ class Period
|
|
186
186
|
|
187
187
|
def self.chunk_syms
|
188
188
|
[:day, :week, :biweek, :semimonth, :month, :bimonth,
|
189
|
-
:quarter, :year, :irregular]
|
189
|
+
:quarter, :half, :year, :irregular]
|
190
190
|
end
|
191
191
|
|
192
192
|
def self.chunk_sym_to_days(sym)
|
@@ -238,10 +238,7 @@ class Period
|
|
238
238
|
end
|
239
239
|
end
|
240
240
|
|
241
|
-
#
|
242
|
-
# number of days between statements, so it will not consider all
|
243
|
-
# possible chunks, only :year, :quarter, :month, and :week. And
|
244
|
-
# distinguishing between :semimonth and :biweek is impossible in
|
241
|
+
# Distinguishing between :semimonth and :biweek is impossible in
|
245
242
|
# some cases since a :semimonth can be 14 days just like a :biweek.
|
246
243
|
# This ignores that possiblity and requires a :semimonth to be at
|
247
244
|
# least 15 days.
|
@@ -354,6 +351,9 @@ class Period
|
|
354
351
|
if first.beginning_of_year? && last.end_of_year? &&
|
355
352
|
(365..366) === last - first + 1
|
356
353
|
:year
|
354
|
+
elsif first.beginning_of_half? && last.end_of_half? &&
|
355
|
+
(180..183) === last - first + 1
|
356
|
+
:half
|
357
357
|
elsif first.beginning_of_quarter? && last.end_of_quarter? &&
|
358
358
|
(90..92) === last - first + 1
|
359
359
|
:quarter
|
@@ -388,6 +388,8 @@ class Period
|
|
388
388
|
case Period.days_to_chunk_sym(length)
|
389
389
|
when :year
|
390
390
|
'Year'
|
391
|
+
when :half
|
392
|
+
'Half'
|
391
393
|
when :quarter
|
392
394
|
'Quarter'
|
393
395
|
when :bimonth
|
@@ -491,7 +493,7 @@ class Period
|
|
491
493
|
when :day
|
492
494
|
chunk_end = chunk_start
|
493
495
|
else
|
494
|
-
|
496
|
+
raise ArgumentError, "invalid chunk size '#{size}'"
|
495
497
|
end
|
496
498
|
if chunk_end <= last
|
497
499
|
result << Period.new(chunk_start, chunk_end)
|
data/lib/fat_core/version.rb
CHANGED
data/spec/lib/period_spec.rb
CHANGED
@@ -50,6 +50,14 @@ describe Period do
|
|
50
50
|
expect(pd.first).to eq(Date.parse('2012-07-01'))
|
51
51
|
expect(pd.last).to eq(Date.parse('2012-12-31'))
|
52
52
|
|
53
|
+
pd = Period.parse_phrase('from 1H')
|
54
|
+
expect(pd.first).to eq(Date.parse('2012-01-01'))
|
55
|
+
expect(pd.last).to eq(Date.parse('2012-06-30'))
|
56
|
+
|
57
|
+
pd = Period.parse_phrase('to 2H')
|
58
|
+
expect(pd.first).to eq(Date.parse('2012-07-01'))
|
59
|
+
expect(pd.last).to eq(Date.parse('2012-12-31'))
|
60
|
+
|
53
61
|
pd = Period.parse_phrase('from 2Q')
|
54
62
|
expect(pd.first).to eq(Date.parse('2012-04-01'))
|
55
63
|
expect(pd.last).to eq(Date.parse('2012-06-30'))
|
@@ -118,7 +126,7 @@ describe Period do
|
|
118
126
|
end
|
119
127
|
|
120
128
|
it 'should know what the valid chunk syms are' do
|
121
|
-
expect(Period.chunk_syms.size).to eq
|
129
|
+
expect(Period.chunk_syms.size).to eq(10)
|
122
130
|
end
|
123
131
|
|
124
132
|
it 'should know the days in a chunk sym' do
|
@@ -154,6 +162,7 @@ describe Period do
|
|
154
162
|
|
155
163
|
it 'should know the chunk sym for given days but only :year, :quarter, :month' do
|
156
164
|
(356..376).each { |d| expect(Period.days_to_chunk_sym(d)).to eq(:year) }
|
165
|
+
(180..183).each { |d| expect(Period.days_to_chunk_sym(d)).to eq(:half) }
|
157
166
|
(86..96).each { |d| expect(Period.days_to_chunk_sym(d)).to eq(:quarter) }
|
158
167
|
(28..31).each { |d| expect(Period.days_to_chunk_sym(d)).to eq(:month) }
|
159
168
|
expect(Period.days_to_chunk_sym(7)).to eq(:week)
|
@@ -162,6 +171,7 @@ describe Period do
|
|
162
171
|
|
163
172
|
it 'should know what to call a chunk based on its size' do
|
164
173
|
expect(Period.new('2011-01-01', '2011-12-31').chunk_name).to eq('Year')
|
174
|
+
expect(Period.new('2011-01-01', '2011-06-30').chunk_name).to eq('Half')
|
165
175
|
expect(Period.new('2011-01-01', '2011-03-31').chunk_name).to eq('Quarter')
|
166
176
|
expect(Period.new('2011-01-01', '2011-02-28').chunk_name)
|
167
177
|
.to eq('Bi-month')
|
@@ -443,6 +453,12 @@ describe Period do
|
|
443
453
|
expect(chunks.last.last.iso).to eq('2012-12-31')
|
444
454
|
end
|
445
455
|
|
456
|
+
it 'should raise error for invalid chunk name' do
|
457
|
+
expect do
|
458
|
+
Period.new('2012-12-28', '2012-12-31').chunks(size: :wally)
|
459
|
+
end.to raise_error(ArgumentError)
|
460
|
+
end
|
461
|
+
|
446
462
|
it 'should not include a partial final chunk by default' do
|
447
463
|
chunks = Period.new('2012-01-01', '2012-03-30').chunks(size: :month)
|
448
464
|
expect(chunks.size).to eq(2)
|
@@ -487,10 +503,13 @@ describe Period do
|
|
487
503
|
expect(chunks.last.last).to eq(Date.parse('2012-03-31'))
|
488
504
|
end
|
489
505
|
|
490
|
-
it 'should be able to its chunk_sym' do
|
506
|
+
it 'should be able to determine its chunk_sym' do
|
491
507
|
expect(Period.new('2013-01-01', '2013-12-31').chunk_sym).to eq(:year)
|
492
508
|
expect(Period.new('2012-01-01', '2013-12-31').chunk_sym).to_not eq(:year)
|
493
509
|
|
510
|
+
expect(Period.new('2013-01-01', '2013-06-30').chunk_sym).to eq(:half)
|
511
|
+
expect(Period.new('2012-01-01', '2013-05-31').chunk_sym).to_not eq(:half)
|
512
|
+
|
494
513
|
expect(Period.new('2013-04-01', '2013-06-30').chunk_sym).to eq(:quarter)
|
495
514
|
expect(Period.new('2013-04-01', '2013-09-30').chunk_sym)
|
496
515
|
.to_not eq(:quarter)
|