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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7a36af9ab31a0faffb0b9128748deb78fa97b8cb56581bcf3b47b8a2a8776d29
4
- data.tar.gz: '089e00bbce43fe66642ef419c9824fab84ab3a6b36aecc586aeb383662c10aa2'
3
+ metadata.gz: 609274b0338a91caf02d5fbf0ed37b4d2621dea51e93a393f9bde86e5287b0ad
4
+ data.tar.gz: cddf0aa8c7087d0705917319090dab8fea710579b697cc79d231f0257a80271d
5
5
  SHA512:
6
- metadata.gz: 83ebcd8b723bd5f95845acf7ecd831293f88ccd15b31caec79d23e1e4bf308d49b02c43556ff85eaebbe9b31d28c683c5cb5dec1418ebfa2f2758790206d731c
7
- data.tar.gz: 7e19c54d5e179b20ff715e28b2ae191ada78ee75553832b07b48b3bba82ea617494208de44ae18900f45258ffb0de7be60fd5beadf200a7182921f690aebd9a7
6
+ metadata.gz: 3da42e489a2dc3a1d8b42191e589e675a71466048a70b1b2d04f430b2f3f34685f0c137194952a7c4ec33c117cf227b1143670409353351af9b8531492efc93b
7
+ data.tar.gz: e91123fa17ff8a9f47553652a302316418aaf2f5fe5eee587b45ecb9b27799ad20b39b9e1af350e4453ee69f19f4a8cd6a595ed82df2247c5bc8084c664768de
data/.travis.yml CHANGED
@@ -3,4 +3,4 @@ rvm:
3
3
  - 2.5
4
4
  - 2.6
5
5
  - 2.7
6
- - ruby-head
6
+ - 3.0
@@ -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
- if phrase =~ /\Afrom (.*) to (.*)\z/
90
+ case phrase
91
+ when /\Afrom (.*) to (.*)\z/
93
92
  from_phrase = $1
94
93
  to_phrase = $2
95
- elsif phrase =~ /\Afrom (.*)\z/
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 a
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 adjusted. The
477
- # reason for allowing a bit of tolerance for the larger periods is that
478
- # financial statements meant to cover a given calendar period are often short
479
- # or long by a few days due to such things as weekends, holidays, or
480
- # accounting convenience. For example, a bank might issuer "monthly"
481
- # statements approximately every 30 days, but issue them earlier or later to
482
- # avoid having the closing date fall on a weekend or holiday. We still want to
483
- # be able to recognize them as "monthly", even though the period covered might
484
- # be a few days shorter or longer than any possible calendar month. You can
485
- # eliminate this "fudge factor" by setting the `tolerance_pct` to zero. If
486
- # the number of days corresponds to none of the defined calendar periods,
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 [Numberic] the percent deviation allowed, e.g. 10 => 10%
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 [:semimonth, :biweek, :week, :day].include?(chunk)
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
- elsif partial_last
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
@@ -1,3 +1,3 @@
1
1
  module FatPeriod
2
- VERSION = '1.2.0'.freeze
2
+ VERSION = '1.2.1'.freeze
3
3
  end
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.0
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: 2020-04-13 00:00:00.000000000 Z
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.0.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: []