fat_period 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.envrc +1 -0
- data/.ruby-version +1 -0
- data/fat_period.gemspec +2 -2
- data/lib/fat_period/period.rb +29 -4
- data/lib/fat_period/version.rb +1 -1
- metadata +12 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe15db09e24f9ddf7264fdf8862ea51bacb0fb88da8b21727c44ce0c0a4f930c
|
4
|
+
data.tar.gz: 0ea19cc89dfa940268938ccf2d8f3abd949e2c1a405d158410c0f928c8c6d64a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4270dcbd82522aeb3781205e4598b52f15cc2c3b352709b500ffb6db6cd80a5691416d3a3abed2cf132fc0de8d5b05a14e934d14100c984293893cc4b3de378
|
7
|
+
data.tar.gz: 82458a341811b97e30393360fc81b02acad7d4b8446ce616b7c84d237e11ec037fa85790d241c02c9874924733ac0895fd648f7b0ec3d83f8de04ccd9eaf1372
|
data/.envrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
PATH_add .bundle/bin
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.2.2
|
data/fat_period.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = 'fat_period'
|
8
8
|
spec.version = FatPeriod::VERSION
|
9
9
|
spec.authors = ['Daniel E. Doherty']
|
10
|
-
spec.email = ['ded
|
10
|
+
spec.email = ['ded@ddoherty.net']
|
11
11
|
|
12
12
|
spec.summary = %q{Implements a Period class as a Range of Dates.}
|
13
13
|
spec.homepage = 'https://github.com/ddoherty03/fat_period'
|
@@ -28,5 +28,5 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_development_dependency 'pry-doc'
|
29
29
|
spec.add_development_dependency 'simplecov'
|
30
30
|
|
31
|
-
spec.add_runtime_dependency 'fat_core', '>=
|
31
|
+
spec.add_runtime_dependency 'fat_core', '>= 5.1.0'
|
32
32
|
end
|
data/lib/fat_period/period.rb
CHANGED
@@ -27,8 +27,8 @@ class Period
|
|
27
27
|
# @raise [ArgumentError] if first date is later than last date
|
28
28
|
# @return [Period]
|
29
29
|
def initialize(first, last)
|
30
|
-
@first = Date.
|
31
|
-
@last = Date.
|
30
|
+
@first = Date.ensure(first).freeze
|
31
|
+
@last = Date.ensure(last).freeze
|
32
32
|
freeze
|
33
33
|
|
34
34
|
raise ArgumentError, "Period's first date is later than its last date" if @first > @last
|
@@ -70,7 +70,7 @@ class Period
|
|
70
70
|
|
71
71
|
PHRASE_RE = %r{\A
|
72
72
|
# One or both of from and to parts
|
73
|
-
(((from)?\s
|
73
|
+
(((from)?\s*(?<from_part>[-_a-z0-9]+)\s*)?
|
74
74
|
(to\s+(?<to_part>[-_a-z0-9]+))?)
|
75
75
|
# Wholly optional chunk part
|
76
76
|
(\s+per\s+(?<chunk_part>\w+))?\z}xi
|
@@ -166,6 +166,31 @@ class Period
|
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
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
|
+
|
169
194
|
# A concise way to print out Periods for inspection as
|
170
195
|
# 'Period(YYYY-MM-DD..YYYY-MM-DD)'.
|
171
196
|
#
|
@@ -371,7 +396,7 @@ class Period
|
|
371
396
|
chunk = chunk.to_sym
|
372
397
|
raise ArgumentError, "unknown chunk name: #{chunk}" unless CHUNKS.include?(chunk)
|
373
398
|
|
374
|
-
date = Date.
|
399
|
+
date = Date.ensure(date)
|
375
400
|
method = "#{chunk}_containing".to_sym
|
376
401
|
send(method, date)
|
377
402
|
end
|
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.
|
4
|
+
version: 1.5.0
|
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: 2024-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -114,23 +114,25 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
117
|
+
version: 5.1.0
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
125
|
-
description:
|
124
|
+
version: 5.1.0
|
125
|
+
description:
|
126
126
|
email:
|
127
|
-
- ded
|
127
|
+
- ded@ddoherty.net
|
128
128
|
executables: []
|
129
129
|
extensions: []
|
130
130
|
extra_rdoc_files: []
|
131
131
|
files:
|
132
|
+
- ".envrc"
|
132
133
|
- ".gitignore"
|
133
134
|
- ".rspec"
|
135
|
+
- ".ruby-version"
|
134
136
|
- ".simplecov"
|
135
137
|
- ".travis.yml"
|
136
138
|
- Gemfile
|
@@ -147,7 +149,7 @@ files:
|
|
147
149
|
homepage: https://github.com/ddoherty03/fat_period
|
148
150
|
licenses: []
|
149
151
|
metadata: {}
|
150
|
-
post_install_message:
|
152
|
+
post_install_message:
|
151
153
|
rdoc_options: []
|
152
154
|
require_paths:
|
153
155
|
- lib
|
@@ -162,8 +164,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
164
|
- !ruby/object:Gem::Version
|
163
165
|
version: '0'
|
164
166
|
requirements: []
|
165
|
-
rubygems_version: 3.
|
166
|
-
signing_key:
|
167
|
+
rubygems_version: 3.5.18
|
168
|
+
signing_key:
|
167
169
|
specification_version: 4
|
168
170
|
summary: Implements a Period class as a Range of Dates.
|
169
171
|
test_files: []
|