fat_period 1.5.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.envrc +6 -0
- data/.github/workflows/gem-push.yml +48 -0
- data/Gemfile +12 -0
- data/Rakefile +4 -1
- data/fat_period.gemspec +4 -11
- data/lib/fat_period/date.rb +0 -49
- data/lib/fat_period/period.rb +96 -107
- data/lib/fat_period/version.rb +1 -1
- data/lib/fat_period.rb +6 -0
- metadata +6 -105
- data/.ruby-version +0 -1
- data/.simplecov +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 875ad1917477c27f17278fb0d5aad18423f4dcf52f32c9957651c829a1164f4b
|
4
|
+
data.tar.gz: 1495e04adb60e49dfc26f1b94c9699a129f30b7a15c36e9fa82d0e68d87ed183
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7e5ece151032b3ce11aad94225ef649c9e217a2d9239406f3ef030b335169cc33a130ff860b11b65a2e9d90ab4d9f900eb6df713f904beb9d841a7068ebcb96
|
7
|
+
data.tar.gz: 91a94d16666150d0eba4cd4bd5cb24813150d714f2e534a15746bd70119e87996d39940d8da40c5ab7589707975fe53f60a53cd4ae7d9bd58254b710d7d3c4ee
|
data/.envrc
CHANGED
@@ -0,0 +1,48 @@
|
|
1
|
+
name: Ruby Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ "master" ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ "master" ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
build:
|
11
|
+
name: Build + Publish
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
permissions:
|
14
|
+
contents: read
|
15
|
+
packages: write
|
16
|
+
|
17
|
+
steps:
|
18
|
+
- uses: actions/checkout@v4
|
19
|
+
- name: Set up Ruby 2.6
|
20
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
21
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
22
|
+
# uses: ruby/setup-ruby@v1
|
23
|
+
uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
|
24
|
+
with:
|
25
|
+
ruby-version: 2.6.x
|
26
|
+
|
27
|
+
- name: Publish to GPR
|
28
|
+
run: |
|
29
|
+
mkdir -p $HOME/.gem
|
30
|
+
touch $HOME/.gem/credentials
|
31
|
+
chmod 0600 $HOME/.gem/credentials
|
32
|
+
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
33
|
+
gem build *.gemspec
|
34
|
+
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
|
35
|
+
env:
|
36
|
+
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
|
37
|
+
OWNER: ${{ github.repository_owner }}
|
38
|
+
|
39
|
+
- name: Publish to RubyGems
|
40
|
+
run: |
|
41
|
+
mkdir -p $HOME/.gem
|
42
|
+
touch $HOME/.gem/credentials
|
43
|
+
chmod 0600 $HOME/.gem/credentials
|
44
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
45
|
+
gem build *.gemspec
|
46
|
+
gem push *.gem
|
47
|
+
env:
|
48
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
data/Gemfile
CHANGED
@@ -2,3 +2,15 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in fat_period.gemspec
|
4
4
|
gemspec
|
5
|
+
|
6
|
+
gem 'bundler'
|
7
|
+
gem 'debug'
|
8
|
+
gem 'pry'
|
9
|
+
gem 'pry-doc'
|
10
|
+
gem 'rake'
|
11
|
+
gem 'rspec'
|
12
|
+
gem 'rubocop'
|
13
|
+
gem 'rubocop-rspec'
|
14
|
+
gem 'rubocop-performance'
|
15
|
+
gem 'rubocop-rake'
|
16
|
+
gem 'rubocop-shopify'
|
data/Rakefile
CHANGED
data/fat_period.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
|
2
3
|
lib = File.expand_path('../lib', __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'fat_period/version'
|
@@ -9,10 +10,10 @@ Gem::Specification.new do |spec|
|
|
9
10
|
spec.authors = ['Daniel E. Doherty']
|
10
11
|
spec.email = ['ded@ddoherty.net']
|
11
12
|
|
12
|
-
spec.summary =
|
13
|
+
spec.summary = 'Implements a Period class as a Range of Dates.'
|
13
14
|
spec.homepage = 'https://github.com/ddoherty03/fat_period'
|
14
15
|
|
15
|
-
spec.files =
|
16
|
+
spec.files = %x(git ls-files -z).split("\x0").reject do |f|
|
16
17
|
f.match(%r{^(test|spec|features)/})
|
17
18
|
end
|
18
19
|
# Don't install any executables.
|
@@ -20,13 +21,5 @@ Gem::Specification.new do |spec|
|
|
20
21
|
# spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
22
|
spec.require_paths = ['lib']
|
22
23
|
|
23
|
-
spec.
|
24
|
-
spec.add_development_dependency 'rake'
|
25
|
-
spec.add_development_dependency 'rspec'
|
26
|
-
spec.add_development_dependency 'debug', '>= 1.0.0'
|
27
|
-
spec.add_development_dependency 'pry'
|
28
|
-
spec.add_development_dependency 'pry-doc'
|
29
|
-
spec.add_development_dependency 'simplecov'
|
30
|
-
|
31
|
-
spec.add_runtime_dependency 'fat_core', '>= 5.1.0'
|
24
|
+
spec.add_dependency 'fat_core', '>= 5.4'
|
32
25
|
end
|
data/lib/fat_period/date.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'date'
|
2
|
-
|
3
1
|
module FatPeriod
|
4
2
|
# An extension of Date for methods useful with respect to FatPeriod::Periods.
|
5
3
|
module Date
|
@@ -20,53 +18,6 @@ module FatPeriod
|
|
20
18
|
require 'fat_period'
|
21
19
|
Period.new(beginning_of_chunk(chunk), end_of_chunk(chunk))
|
22
20
|
end
|
23
|
-
|
24
|
-
# Return a period representing a chunk containing a given Date.
|
25
|
-
def day_containing
|
26
|
-
Period.new(self, self)
|
27
|
-
end
|
28
|
-
|
29
|
-
def week_containing
|
30
|
-
Period.new(self.beginning_of_week, self.end_of_week)
|
31
|
-
end
|
32
|
-
|
33
|
-
def biweek_containing
|
34
|
-
Period.new(self.beginning_of_biweek, self.end_of_biweek)
|
35
|
-
end
|
36
|
-
|
37
|
-
def semimonth_containing
|
38
|
-
Period.new(self.beginning_of_semimonth, self.end_of_semimonth)
|
39
|
-
end
|
40
|
-
|
41
|
-
def month_containing
|
42
|
-
Period.new(self.beginning_of_month, self.end_of_month)
|
43
|
-
end
|
44
|
-
|
45
|
-
def bimonth_containing
|
46
|
-
Period.new(self.beginning_of_bimonth, self.end_of_bimonth)
|
47
|
-
end
|
48
|
-
|
49
|
-
def quarter_containing
|
50
|
-
Period.new(self.beginning_of_quarter, self.end_of_quarter)
|
51
|
-
end
|
52
|
-
|
53
|
-
def half_containing
|
54
|
-
Period.new(self.beginning_of_half, self.end_of_half)
|
55
|
-
end
|
56
|
-
|
57
|
-
def year_containing
|
58
|
-
Period.new(self.beginning_of_year, self.end_of_year)
|
59
|
-
end
|
60
|
-
|
61
|
-
def chunk_containing(chunk)
|
62
|
-
raise ArgumentError, 'chunk is nil' unless chunk
|
63
|
-
|
64
|
-
chunk = chunk.to_sym
|
65
|
-
raise ArgumentError, "unknown chunk name: #{chunk}" unless CHUNKS.include?(chunk)
|
66
|
-
|
67
|
-
method = "#{chunk}_containing".to_sym
|
68
|
-
send(method, self)
|
69
|
-
end
|
70
21
|
end
|
71
22
|
end
|
72
23
|
|
data/lib/fat_period/period.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
+
require 'active_support'
|
1
2
|
require 'fat_core/date'
|
2
|
-
require 'fat_core/range'
|
3
|
-
require 'fat_core/string'
|
4
3
|
|
5
4
|
# The Period class represents a range of Dates and supports a variety of
|
6
5
|
# operations on those ranges.
|
@@ -27,8 +26,8 @@ class Period
|
|
27
26
|
# @raise [ArgumentError] if first date is later than last date
|
28
27
|
# @return [Period]
|
29
28
|
def initialize(first, last)
|
30
|
-
@first = Date.
|
31
|
-
@last = Date.
|
29
|
+
@first = Date.ensure_date(first).freeze
|
30
|
+
@last = Date.ensure_date(last).freeze
|
32
31
|
freeze
|
33
32
|
|
34
33
|
raise ArgumentError, "Period's first date is later than its last date" if @first > @last
|
@@ -36,9 +35,6 @@ class Period
|
|
36
35
|
|
37
36
|
# These need to come after initialize is defined
|
38
37
|
|
39
|
-
# Period from commercial beginning of time to today
|
40
|
-
TO_DATE = Period.new(Date::BOT, Date.current)
|
41
|
-
|
42
38
|
# Period from commercial beginning of time to commercial end of time.
|
43
39
|
FOREVER = Period.new(Date::BOT, Date::EOT)
|
44
40
|
|
@@ -68,59 +64,72 @@ class Period
|
|
68
64
|
Period.new(first, second) if first && second
|
69
65
|
end
|
70
66
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
67
|
+
# Return a Period either from a given String or other type that can
|
68
|
+
# reasonably converted to a Period.
|
69
|
+
#
|
70
|
+
# @example
|
71
|
+
# Period.ensure('2014-11').inspect #=> Period('2014-11-01..2014-11-30')
|
72
|
+
# pd = Period.parse('2011')
|
73
|
+
# Period.ensure(pd).inspect #=> Period('2011-01-01..2011-12-31')
|
74
|
+
#
|
75
|
+
# @param prd [String|Period] or any candidate for conversion to Period
|
76
|
+
# @return Period correspondign to prd parameter
|
77
|
+
def self.ensure(prd)
|
78
|
+
prd.to_period if prd.respond_to?(:to_period)
|
79
|
+
case prd
|
80
|
+
when String
|
81
|
+
if prd.match(/from|to/i)
|
82
|
+
Period.parse_phrase(prd).first
|
83
|
+
else
|
84
|
+
Period.parse(prd)
|
85
|
+
end
|
86
|
+
when Period
|
87
|
+
prd
|
88
|
+
end
|
89
|
+
end
|
79
90
|
|
80
|
-
# Return an
|
81
|
-
#
|
82
|
-
# optionally
|
83
|
-
#
|
84
|
-
#
|
85
|
-
#
|
91
|
+
# Return an Array of Periods from a String phrase in which the from spec is
|
92
|
+
# introduced with 'from' and, optionally, the to spec is introduced with
|
93
|
+
# 'to' and optionally a 'per' clause is introduced by 'per'. A phrase with
|
94
|
+
# only a to spec is treated the same as one with only a from spec. If
|
95
|
+
# neither 'from' nor 'to' appear in phrase, treat the string before any
|
96
|
+
# per-clause as a from spec.
|
86
97
|
#
|
87
98
|
# @example
|
88
99
|
# Period.parse_phrase('from 2014-11 to 2015-3Q') #=> [Period('2014-11-01..2015-09-30')]
|
89
100
|
# Period.parse_phrase('from 2014-11') #=> [Period('2014-11-01..2014-11-30')]
|
90
101
|
# Period.parse_phrase('from 2015-3Q') #=> [Period('2015-09-01..2015-12-31')]
|
91
102
|
# Period.parse_phrase('to 2015-3Q') #=> [Period('2015-09-01..2015-12-31')]
|
92
|
-
# Period.parse_phrase('
|
93
|
-
# Period.parse_phrase('
|
94
|
-
#
|
95
|
-
#
|
96
|
-
#
|
97
|
-
#
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
elsif mm[:from_part].nil? && mm[:to_part]
|
111
|
-
from_part = mm[:to_part]
|
112
|
-
to_part = nil
|
103
|
+
# Period.parse_phrase('2015-3Q') #=> [Period('2015-09-01..2015-12-31')]
|
104
|
+
# Period.parse_phrase('to 2015-3Q per week') #=> [Period('2015-09-01..2015-09-04')...]
|
105
|
+
# Period.parse_phrase('2015-3Q per month') #=> [Period('2015-09-01..2015-09-30')...]
|
106
|
+
#
|
107
|
+
# @param phrase [String] with 'from <spec> [to <spec>] [per chunk]'
|
108
|
+
# @return [Period] translated from phrase
|
109
|
+
def self.parse_phrase(phrase, partial_first: true, partial_last: true, round_up_last: false)
|
110
|
+
phrase = phrase.clean
|
111
|
+
case phrase
|
112
|
+
when /\Afrom\s+([^\s]+)\s+to\s+([^\s]+)(\s+per\s+[^\s]+)?\z/i
|
113
|
+
from_phrase = $1
|
114
|
+
to_phrase = $2
|
115
|
+
when /\Afrom\s+([^\s]+)(\s+per\s+[^\s]+)?\z/, /\Ato\s+([^\s]+)(\s+per\s+[^\s]+)?\z/i
|
116
|
+
from_phrase = $1
|
117
|
+
to_phrase = nil
|
118
|
+
when /\A([^\s]+)(\s+per\s+[^\s]+)?\z/
|
119
|
+
from_phrase = $1
|
120
|
+
to_phrase = nil
|
113
121
|
else
|
114
|
-
|
115
|
-
to_part = mm[:to_part]
|
122
|
+
raise ArgumentError, "unintelligible period phrase: '#{phrase}''"
|
116
123
|
end
|
124
|
+
# Return an Array of periods divided by chunks if any.
|
125
|
+
whole_period = parse(from_phrase, to_phrase)
|
126
|
+
if phrase =~ /per\s+(?<chunk>[a-z_]+)/i
|
127
|
+
chunk_size = Regexp.last_match[:chunk].downcase.to_sym
|
128
|
+
raise ArgumentError, "invalid chunk size #{chunk_size}" unless CHUNKS.include?(chunk_size)
|
117
129
|
|
118
|
-
|
119
|
-
if mm[:chunk_part].nil?
|
120
|
-
[whole_period]
|
130
|
+
whole_period.chunks(size: chunk_size, partial_first:, partial_last:, round_up_last:)
|
121
131
|
else
|
122
|
-
whole_period
|
123
|
-
partial_last: partial_last, round_up_last: round_up_last)
|
132
|
+
[whole_period]
|
124
133
|
end
|
125
134
|
end
|
126
135
|
|
@@ -166,31 +175,6 @@ class Period
|
|
166
175
|
end
|
167
176
|
end
|
168
177
|
|
169
|
-
# Convert a string or Period into a Period object, if the string is parsable
|
170
|
-
# as a period.
|
171
|
-
#
|
172
|
-
# @example
|
173
|
-
# Period.ensure('2023-1q') #=> Period 2023-01-01..2023-03-31
|
174
|
-
# pd = Period.new('2016-01-01', '2016-12-31')
|
175
|
-
# Period.ensure(pd) #=> pd # No effect
|
176
|
-
#
|
177
|
-
# @return [Period] either parsed String or same Period
|
178
|
-
def self.ensure(pd)
|
179
|
-
case pd
|
180
|
-
when Period
|
181
|
-
pd
|
182
|
-
when String
|
183
|
-
if pd.match?(/\s*from/i)
|
184
|
-
# Ignore any chunk modifier, 'per'
|
185
|
-
Period.parse_phrase(pd).first
|
186
|
-
else
|
187
|
-
Period.parse(pd)
|
188
|
-
end
|
189
|
-
else
|
190
|
-
raise UserError, "can't ensure `#{pd}` of #{pd.class} is a Period"
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
178
|
# A concise way to print out Periods for inspection as
|
195
179
|
# 'Period(YYYY-MM-DD..YYYY-MM-DD)'.
|
196
180
|
#
|
@@ -216,7 +200,7 @@ class Period
|
|
216
200
|
# @param other [Period] @return [Integer] -1 if self < other; 0 if self ==
|
217
201
|
# other; 1 if self > other
|
218
202
|
def <=>(other)
|
219
|
-
return
|
203
|
+
return unless other.is_a?(Period)
|
220
204
|
|
221
205
|
[first, last] <=> [other.first, other.last]
|
222
206
|
end
|
@@ -235,7 +219,7 @@ class Period
|
|
235
219
|
end
|
236
220
|
|
237
221
|
def eql?(other)
|
238
|
-
return
|
222
|
+
return false unless other.is_a?(Period)
|
239
223
|
|
240
224
|
hash == other.hash
|
241
225
|
end
|
@@ -250,7 +234,7 @@ class Period
|
|
250
234
|
|
251
235
|
to_range.cover?(date)
|
252
236
|
end
|
253
|
-
|
237
|
+
alias_method :===, :contains?
|
254
238
|
|
255
239
|
include Enumerable
|
256
240
|
|
@@ -258,15 +242,10 @@ class Period
|
|
258
242
|
|
259
243
|
# Yield each day in this Period.
|
260
244
|
def each
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
d += 1.day
|
266
|
-
end
|
267
|
-
self
|
268
|
-
else
|
269
|
-
to_enum(:each)
|
245
|
+
d = first
|
246
|
+
while d <= last
|
247
|
+
yield d
|
248
|
+
d += 1.day
|
270
249
|
end
|
271
250
|
end
|
272
251
|
|
@@ -284,8 +263,8 @@ class Period
|
|
284
263
|
def size
|
285
264
|
(last - first + 1).to_i
|
286
265
|
end
|
287
|
-
|
288
|
-
|
266
|
+
alias_method :length, :size
|
267
|
+
alias_method :days, :size
|
289
268
|
|
290
269
|
# Return the fractional number of months in the period. By default, use the
|
291
270
|
# average number of days in a month, but allow the user to override the
|
@@ -331,8 +310,17 @@ class Period
|
|
331
310
|
|
332
311
|
# An Array of the valid Symbols for calendar chunks plus the Symbol :irregular
|
333
312
|
# for other periods.
|
334
|
-
CHUNKS = %i[
|
335
|
-
|
313
|
+
CHUNKS = %i[
|
314
|
+
day
|
315
|
+
week
|
316
|
+
biweek
|
317
|
+
semimonth
|
318
|
+
month
|
319
|
+
bimonth
|
320
|
+
quarter
|
321
|
+
half
|
322
|
+
year
|
323
|
+
].freeze
|
336
324
|
|
337
325
|
CHUNK_ORDER = {}
|
338
326
|
CHUNKS.each_with_index do |c, i|
|
@@ -342,13 +330,17 @@ class Period
|
|
342
330
|
|
343
331
|
# An Array of Ranges for the number of days that can be covered by each chunk.
|
344
332
|
CHUNK_RANGE = {
|
345
|
-
day: (1..1),
|
346
|
-
|
347
|
-
|
333
|
+
day: (1..1),
|
334
|
+
week: (7..7),
|
335
|
+
biweek: (14..14),
|
336
|
+
semimonth: (15..16),
|
337
|
+
month: (28..31),
|
338
|
+
bimonth: (59..62),
|
339
|
+
quarter: (90..92),
|
340
|
+
half: (180..183),
|
341
|
+
year: (365..366)
|
348
342
|
}.freeze
|
349
343
|
|
350
|
-
private_constant :CHUNK_ORDER, :CHUNK_RANGE
|
351
|
-
|
352
344
|
def self.chunk_cmp(chunk1, chunk2)
|
353
345
|
CHUNK_ORDER[chunk1] <=> CHUNK_ORDER[chunk2]
|
354
346
|
end
|
@@ -396,7 +388,7 @@ class Period
|
|
396
388
|
chunk = chunk.to_sym
|
397
389
|
raise ArgumentError, "unknown chunk name: #{chunk}" unless CHUNKS.include?(chunk)
|
398
390
|
|
399
|
-
date = Date.
|
391
|
+
date = Date.ensure_date(date)
|
400
392
|
method = "#{chunk}_containing".to_sym
|
401
393
|
send(method, date)
|
402
394
|
end
|
@@ -636,8 +628,8 @@ class Period
|
|
636
628
|
# @param round_up_last [Boolean] allow the last period in the returned array
|
637
629
|
# to extend beyond the end of self.
|
638
630
|
# @return [Array<Period>] periods that subdivide self into chunks of size, `size`
|
639
|
-
def chunks(size: :month, partial_first:
|
640
|
-
|
631
|
+
def chunks(size: :month, partial_first: true, partial_last: true,
|
632
|
+
round_up_last: false)
|
641
633
|
chunk_size = size.to_sym
|
642
634
|
raise ArgumentError, "unknown chunk size '#{chunk_size}'" unless CHUNKS.include?(chunk_size)
|
643
635
|
|
@@ -661,7 +653,6 @@ class Period
|
|
661
653
|
return result
|
662
654
|
end
|
663
655
|
|
664
|
-
# The first chunk
|
665
656
|
chunk_start = first.dup
|
666
657
|
chunk_end = chunk_start.end_of_chunk(chunk_size)
|
667
658
|
if chunk_start.beginning_of_chunk?(chunk_size) || partial_first
|
@@ -670,16 +661,14 @@ class Period
|
|
670
661
|
end
|
671
662
|
chunk_start = chunk_end + 1.day
|
672
663
|
chunk_end = chunk_start.end_of_chunk(chunk_size)
|
673
|
-
|
674
664
|
# Add Whole chunks
|
675
665
|
while chunk_end <= last
|
676
666
|
result << Period.new(chunk_start, chunk_end)
|
677
667
|
chunk_start = chunk_end + 1.day
|
678
668
|
chunk_end = chunk_start.end_of_chunk(chunk_size)
|
679
669
|
end
|
680
|
-
|
681
670
|
# Possibly append the final chunk to result
|
682
|
-
if chunk_start
|
671
|
+
if chunk_start < last
|
683
672
|
if round_up_last
|
684
673
|
result << Period.new(chunk_start, chunk_end)
|
685
674
|
elsif partial_last
|
@@ -772,8 +761,8 @@ class Period
|
|
772
761
|
Period.new(result.first, result.last)
|
773
762
|
end
|
774
763
|
end
|
775
|
-
|
776
|
-
|
764
|
+
alias_method :&, :intersection
|
765
|
+
alias_method :narrow_to, :intersection
|
777
766
|
|
778
767
|
# Return the Period that is the union of self with `other` or nil if
|
779
768
|
# they neither overlap nor are contiguous
|
@@ -790,11 +779,11 @@ class Period
|
|
790
779
|
# @return [Period, nil] self union `other`?
|
791
780
|
def union(other)
|
792
781
|
result = to_range.union(other.to_range)
|
793
|
-
return
|
782
|
+
return if result.nil?
|
794
783
|
|
795
784
|
Period.new(result.first, result.last)
|
796
785
|
end
|
797
|
-
|
786
|
+
alias_method :+, :union
|
798
787
|
|
799
788
|
# Return an array of periods that are this period excluding any overlap with
|
800
789
|
# other. If there is no overlap, return an array with a period equal to self
|
@@ -812,7 +801,7 @@ class Period
|
|
812
801
|
ranges = to_range.difference(other.to_range)
|
813
802
|
ranges.each.map { |r| Period.new(r.first, r.last) }
|
814
803
|
end
|
815
|
-
|
804
|
+
alias_method :-, :difference
|
816
805
|
|
817
806
|
# Return whether this period overlaps the `other` period. To overlap, the
|
818
807
|
# periods must have at least one day in common.
|
data/lib/fat_period/version.rb
CHANGED
data/lib/fat_period.rb
CHANGED
metadata
CHANGED
@@ -1,127 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fat_period
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel E. Doherty
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: bundler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rspec
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: debug
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 1.0.0
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 1.0.0
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: pry
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: pry-doc
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: simplecov
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
13
|
- !ruby/object:Gem::Dependency
|
112
14
|
name: fat_core
|
113
15
|
requirement: !ruby/object:Gem::Requirement
|
114
16
|
requirements:
|
115
17
|
- - ">="
|
116
18
|
- !ruby/object:Gem::Version
|
117
|
-
version: 5.
|
19
|
+
version: '5.4'
|
118
20
|
type: :runtime
|
119
21
|
prerelease: false
|
120
22
|
version_requirements: !ruby/object:Gem::Requirement
|
121
23
|
requirements:
|
122
24
|
- - ">="
|
123
25
|
- !ruby/object:Gem::Version
|
124
|
-
version: 5.
|
26
|
+
version: '5.4'
|
125
27
|
description:
|
126
28
|
email:
|
127
29
|
- ded@ddoherty.net
|
@@ -130,10 +32,9 @@ extensions: []
|
|
130
32
|
extra_rdoc_files: []
|
131
33
|
files:
|
132
34
|
- ".envrc"
|
35
|
+
- ".github/workflows/gem-push.yml"
|
133
36
|
- ".gitignore"
|
134
37
|
- ".rspec"
|
135
|
-
- ".ruby-version"
|
136
|
-
- ".simplecov"
|
137
38
|
- ".travis.yml"
|
138
39
|
- Gemfile
|
139
40
|
- LICENSE.txt
|
@@ -164,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
65
|
- !ruby/object:Gem::Version
|
165
66
|
version: '0'
|
166
67
|
requirements: []
|
167
|
-
rubygems_version: 3.5.
|
68
|
+
rubygems_version: 3.5.22
|
168
69
|
signing_key:
|
169
70
|
specification_version: 4
|
170
71
|
summary: Implements a Period class as a Range of Dates.
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
3.2.2
|
data/.simplecov
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# -*- mode: ruby -*-
|
2
|
-
|
3
|
-
SimpleCov.start do
|
4
|
-
# any custom configs like groups and filters can be here at a central place
|
5
|
-
add_filter '/spec/'
|
6
|
-
add_filter '/tmp/'
|
7
|
-
add_group "Models", "lib/fat_period"
|
8
|
-
# add_group "Core Extension", "lib/ext"
|
9
|
-
# After this many seconds between runs, old coverage stats are thrown out,
|
10
|
-
# so 3600 => 1 hour
|
11
|
-
merge_timeout 3600
|
12
|
-
# Make this true to merge rspec and cucumber coverage together
|
13
|
-
use_merging false
|
14
|
-
command_name 'Rspec'
|
15
|
-
nocov_token 'no_cover'
|
16
|
-
# Branch coverage
|
17
|
-
enable_coverage :branch
|
18
|
-
end
|