fat_period 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/lib/fat_period/period.rb +27 -38
- data/lib/fat_period/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 609274b0338a91caf02d5fbf0ed37b4d2621dea51e93a393f9bde86e5287b0ad
|
4
|
+
data.tar.gz: cddf0aa8c7087d0705917319090dab8fea710579b697cc79d231f0257a80271d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3da42e489a2dc3a1d8b42191e589e675a71466048a70b1b2d04f430b2f3f34685f0c137194952a7c4ec33c117cf227b1143670409353351af9b8531492efc93b
|
7
|
+
data.tar.gz: e91123fa17ff8a9f47553652a302316418aaf2f5fe5eee587b45ecb9b27799ad20b39b9e1af350e4453ee69f19f4a8cd6a595ed82df2247c5bc8084c664768de
|
data/.travis.yml
CHANGED
data/lib/fat_period/period.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
1
|
require 'fat_core/date'
|
4
2
|
require 'fat_core/range'
|
5
3
|
require 'fat_core/string'
|
@@ -89,14 +87,13 @@ class Period
|
|
89
87
|
# @return [Period] translated from phrase
|
90
88
|
def self.parse_phrase(phrase)
|
91
89
|
phrase = phrase.clean
|
92
|
-
|
90
|
+
case phrase
|
91
|
+
when /\Afrom (.*) to (.*)\z/
|
93
92
|
from_phrase = $1
|
94
93
|
to_phrase = $2
|
95
|
-
|
94
|
+
when /\Afrom (.*)\z/, /\Ato (.*)\z/
|
96
95
|
from_phrase = $1
|
97
96
|
to_phrase = nil
|
98
|
-
elsif phrase =~ /\Ato (.*)\z/
|
99
|
-
from_phrase = $1
|
100
97
|
else
|
101
98
|
from_phrase = phrase
|
102
99
|
to_phrase = nil
|
@@ -342,9 +339,7 @@ class Period
|
|
342
339
|
raise ArgumentError, 'chunk is nil' unless chunk
|
343
340
|
|
344
341
|
chunk = chunk.to_sym
|
345
|
-
unless CHUNKS.include?(chunk)
|
346
|
-
raise ArgumentError, "unknown chunk name: #{chunk}"
|
347
|
-
end
|
342
|
+
raise ArgumentError, "unknown chunk name: #{chunk}" unless CHUNKS.include?(chunk)
|
348
343
|
|
349
344
|
date = Date.ensure_date(date)
|
350
345
|
method = "#{chunk}_containing".to_sym
|
@@ -471,20 +466,20 @@ class Period
|
|
471
466
|
end
|
472
467
|
end
|
473
468
|
|
474
|
-
# Return the chunk symbol represented by the number of days given, but allow
|
475
|
-
# deviation from the minimum and maximum number of days for periods larger
|
476
|
-
# than bimonths. The default tolerance is +/-10%, but that can be
|
477
|
-
# reason for allowing a bit of tolerance for the larger
|
478
|
-
# financial statements meant to cover a given calendar
|
479
|
-
# or long by a few days due to such things as
|
480
|
-
# accounting convenience. For example, a bank might
|
481
|
-
# statements approximately every 30 days, but issue them
|
482
|
-
# avoid having the closing date fall on a weekend or
|
483
|
-
# be able to recognize them as "monthly", even
|
484
|
-
# be a few days shorter or longer than any
|
485
|
-
# eliminate this "fudge factor" by setting
|
486
|
-
# the number of days corresponds to none of
|
487
|
-
# return the symbol `:irregular`.
|
469
|
+
# Return the chunk symbol represented by the number of days given, but allow
|
470
|
+
# a deviation from the minimum and maximum number of days for periods larger
|
471
|
+
# than bimonths. The default tolerance is +/-10%, but that can be
|
472
|
+
# adjusted. The reason for allowing a bit of tolerance for the larger
|
473
|
+
# periods is that financial statements meant to cover a given calendar
|
474
|
+
# period are often short or long by a few days due to such things as
|
475
|
+
# weekends, holidays, or accounting convenience. For example, a bank might
|
476
|
+
# issuer "monthly" statements approximately every 30 days, but issue them
|
477
|
+
# earlier or later to avoid having the closing date fall on a weekend or
|
478
|
+
# holiday. We still want to be able to recognize them as "monthly", even
|
479
|
+
# though the period covered might be a few days shorter or longer than any
|
480
|
+
# possible calendar month. You can eliminate this "fudge factor" by setting
|
481
|
+
# the `tolerance_pct` to zero. If the number of days corresponds to none of
|
482
|
+
# the defined calendar periods, return the symbol `:irregular`.
|
488
483
|
#
|
489
484
|
# @example
|
490
485
|
# Period.days_to_chunk(360) #=> :year
|
@@ -493,12 +488,12 @@ class Period
|
|
493
488
|
# Period.days_to_chunk(88, 0) #=> :irregular
|
494
489
|
#
|
495
490
|
# @param days [Integer] the number of days in the period under test
|
496
|
-
# @param tolerance_pct [
|
491
|
+
# @param tolerance_pct [Numeric] the percent deviation allowed, e.g. 10 => 10%
|
497
492
|
# @return [Symbol] symbol for the period corresponding to days number of days
|
498
493
|
def self.days_to_chunk(days, tolerance_pct = 10)
|
499
494
|
result = :irregular
|
500
495
|
CHUNK_RANGE.each_pair do |chunk, rng|
|
501
|
-
if [
|
496
|
+
if %i[semimonth biweek week day].include?(chunk)
|
502
497
|
# Be strict for shorter periods.
|
503
498
|
if rng.cover?(days)
|
504
499
|
result = chunk
|
@@ -589,9 +584,7 @@ class Period
|
|
589
584
|
def chunks(size: :month, partial_first: false, partial_last: false,
|
590
585
|
round_up_last: false)
|
591
586
|
chunk_size = size.to_sym
|
592
|
-
unless CHUNKS.include?(chunk_size)
|
593
|
-
raise ArgumentError, "unknown chunk size '#{chunk_size}'"
|
594
|
-
end
|
587
|
+
raise ArgumentError, "unknown chunk size '#{chunk_size}'" unless CHUNKS.include?(chunk_size)
|
595
588
|
|
596
589
|
containing_period = Period.chunk_containing(first, chunk_size)
|
597
590
|
return [dup] if self == containing_period
|
@@ -618,13 +611,9 @@ class Period
|
|
618
611
|
if chunk_start.beginning_of_chunk?(chunk_size) || partial_first
|
619
612
|
# Keep the first chunk if it's whole or partials allowed
|
620
613
|
result << Period.new(chunk_start, chunk_end)
|
621
|
-
chunk_start = chunk_end + 1.day
|
622
|
-
chunk_end = chunk_start.end_of_chunk(chunk_size)
|
623
|
-
else
|
624
|
-
# Discard the partial first or move to next whole chunk
|
625
|
-
chunk_start = chunk_end + 1.day
|
626
|
-
chunk_end = chunk_start.end_of_chunk(chunk_size)
|
627
614
|
end
|
615
|
+
chunk_start = chunk_end + 1.day
|
616
|
+
chunk_end = chunk_start.end_of_chunk(chunk_size)
|
628
617
|
# Add Whole chunks
|
629
618
|
while chunk_end <= last
|
630
619
|
result << Period.new(chunk_start, chunk_end)
|
@@ -640,15 +629,15 @@ class Period
|
|
640
629
|
else
|
641
630
|
result
|
642
631
|
end
|
643
|
-
|
632
|
+
end
|
633
|
+
if partial_last && !partial_first && result.empty?
|
644
634
|
# Catch the case where the period is too small to make a whole chunk and
|
645
635
|
# partial_first is false, so it did not get included as the initial
|
646
636
|
# partial chunk, yet a partial_last is allowed, so include the whole
|
647
637
|
# period as a partial chunk.
|
648
638
|
result << Period.new(first, last)
|
649
|
-
else
|
650
|
-
result
|
651
639
|
end
|
640
|
+
result
|
652
641
|
end
|
653
642
|
|
654
643
|
# @group Set operations
|
@@ -692,7 +681,7 @@ class Period
|
|
692
681
|
to_range.superset_of?(other.to_range)
|
693
682
|
end
|
694
683
|
|
695
|
-
# Does this period wholly contain but not coincident with `other`?
|
684
|
+
# Does this period wholly contain but is not coincident with `other`?
|
696
685
|
#
|
697
686
|
# @example
|
698
687
|
# Period.parse('2015').proper_superset_of?(Period.parse('2015-2Q')) #=> true
|
data/lib/fat_period/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fat_period
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel E. Doherty
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,7 +108,7 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: 4.8.3
|
111
|
-
description:
|
111
|
+
description:
|
112
112
|
email:
|
113
113
|
- ded-law@ddoherty.net
|
114
114
|
executables: []
|
@@ -132,7 +132,7 @@ files:
|
|
132
132
|
homepage: https://github.com/ddoherty03/fat_period
|
133
133
|
licenses: []
|
134
134
|
metadata: {}
|
135
|
-
post_install_message:
|
135
|
+
post_install_message:
|
136
136
|
rdoc_options: []
|
137
137
|
require_paths:
|
138
138
|
- lib
|
@@ -147,8 +147,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
147
|
- !ruby/object:Gem::Version
|
148
148
|
version: '0'
|
149
149
|
requirements: []
|
150
|
-
rubygems_version: 3.
|
151
|
-
signing_key:
|
150
|
+
rubygems_version: 3.3.3
|
151
|
+
signing_key:
|
152
152
|
specification_version: 4
|
153
153
|
summary: Implements a Period class as a Range of Dates.
|
154
154
|
test_files: []
|