fat_period 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.simplecov +18 -0
- data/fat_period.gemspec +1 -0
- data/lib/fat_period/date.rb +47 -0
- data/lib/fat_period/period.rb +16 -10
- data/lib/fat_period/version.rb +1 -1
- metadata +22 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8592241a9f75949afa4df46469ff74029aa57ad67ac46234717aa751ba4cfef8
|
4
|
+
data.tar.gz: 26658db3f5a219236ae9bc9132cafa58850051fdf5d67c389c51306bcd4cd748
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48f7404be05db83ec57ceb7c2b4e75f584920422067bfc1600163cc58253db0ff3856201df4b6265145a5cbceee534e9d380b1ee44953fbb5fad0ffc772fa0df
|
7
|
+
data.tar.gz: 2ac2dcdb14642e774826f18b6ba7a5bd157fc067bc55495480b7ac91e7e95a21a30217725c4decf5e333e2b8b2cef581df72ee76afa5d18c459b510134c322b1
|
data/.simplecov
ADDED
@@ -0,0 +1,18 @@
|
|
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
|
data/fat_period.gemspec
CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_development_dependency 'debug', '>= 1.0.0'
|
27
27
|
spec.add_development_dependency 'pry'
|
28
28
|
spec.add_development_dependency 'pry-doc'
|
29
|
+
spec.add_development_dependency 'simplecov'
|
29
30
|
|
30
31
|
spec.add_runtime_dependency 'fat_core', '>= 4.8.3'
|
31
32
|
end
|
data/lib/fat_period/date.rb
CHANGED
@@ -20,6 +20,53 @@ module FatPeriod
|
|
20
20
|
require 'fat_period'
|
21
21
|
Period.new(beginning_of_chunk(chunk), end_of_chunk(chunk))
|
22
22
|
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
|
23
70
|
end
|
24
71
|
end
|
25
72
|
|
data/lib/fat_period/period.rb
CHANGED
@@ -31,9 +31,7 @@ class Period
|
|
31
31
|
@last = Date.ensure_date(last).freeze
|
32
32
|
freeze
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
raise ArgumentError, "Period's first date is later than its last date"
|
34
|
+
raise ArgumentError, "Period's first date is later than its last date" if @first > @last
|
37
35
|
end
|
38
36
|
|
39
37
|
# These need to come after initialize is defined
|
@@ -72,11 +70,13 @@ class Period
|
|
72
70
|
|
73
71
|
PHRASE_RE = %r{\A
|
74
72
|
# One or both of from and to parts
|
75
|
-
((from
|
73
|
+
(((from)?\s+(?<from_part>[-_a-z0-9]+)\s*)?
|
76
74
|
(to\s+(?<to_part>[-_a-z0-9]+))?)
|
77
75
|
# Wholly optional chunk part
|
78
76
|
(\s+per\s+(?<chunk_part>\w+))?\z}xi
|
79
77
|
|
78
|
+
private_constant :PHRASE_RE
|
79
|
+
|
80
80
|
# Return an array of periods, either a single period as in `Period.parse`
|
81
81
|
# from a String phrase in which a `from spec` is introduced with 'from' and,
|
82
82
|
# optionally, a `to spec` is introduced with 'to', or a number of periods if
|
@@ -99,8 +99,7 @@ class Period
|
|
99
99
|
#
|
100
100
|
# @param phrase [String] with 'from <spec> to <spec> [per <chunk>]'
|
101
101
|
# @return [Array<Period>] translated from phrase
|
102
|
-
def self.parse_phrase(phrase,
|
103
|
-
partial_first: false, partial_last: false, round_up_last: false)
|
102
|
+
def self.parse_phrase(phrase, partial_first: false, partial_last: false, round_up_last: false)
|
104
103
|
phrase = phrase.downcase.clean
|
105
104
|
mm = phrase.match(PHRASE_RE)
|
106
105
|
raise ArgumentError, "invalid period phrase: `#{phrase}`" unless mm
|
@@ -234,10 +233,15 @@ class Period
|
|
234
233
|
|
235
234
|
# Yield each day in this Period.
|
236
235
|
def each
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
236
|
+
if block_given?
|
237
|
+
d = first
|
238
|
+
while d <= last
|
239
|
+
yield d
|
240
|
+
d += 1.day
|
241
|
+
end
|
242
|
+
self
|
243
|
+
else
|
244
|
+
to_enum(:each)
|
241
245
|
end
|
242
246
|
end
|
243
247
|
|
@@ -318,6 +322,8 @@ class Period
|
|
318
322
|
half: (180..183), year: (365..366)
|
319
323
|
}.freeze
|
320
324
|
|
325
|
+
private_constant :CHUNK_ORDER, :CHUNK_RANGE
|
326
|
+
|
321
327
|
def self.chunk_cmp(chunk1, chunk2)
|
322
328
|
CHUNK_ORDER[chunk1] <=> CHUNK_ORDER[chunk2]
|
323
329
|
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.4.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: 2023-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
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'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: fat_core
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,7 +122,7 @@ dependencies:
|
|
108
122
|
- - ">="
|
109
123
|
- !ruby/object:Gem::Version
|
110
124
|
version: 4.8.3
|
111
|
-
description:
|
125
|
+
description:
|
112
126
|
email:
|
113
127
|
- ded-law@ddoherty.net
|
114
128
|
executables: []
|
@@ -117,6 +131,7 @@ extra_rdoc_files: []
|
|
117
131
|
files:
|
118
132
|
- ".gitignore"
|
119
133
|
- ".rspec"
|
134
|
+
- ".simplecov"
|
120
135
|
- ".travis.yml"
|
121
136
|
- Gemfile
|
122
137
|
- LICENSE.txt
|
@@ -132,7 +147,7 @@ files:
|
|
132
147
|
homepage: https://github.com/ddoherty03/fat_period
|
133
148
|
licenses: []
|
134
149
|
metadata: {}
|
135
|
-
post_install_message:
|
150
|
+
post_install_message:
|
136
151
|
rdoc_options: []
|
137
152
|
require_paths:
|
138
153
|
- lib
|
@@ -147,8 +162,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
162
|
- !ruby/object:Gem::Version
|
148
163
|
version: '0'
|
149
164
|
requirements: []
|
150
|
-
rubygems_version: 3.
|
151
|
-
signing_key:
|
165
|
+
rubygems_version: 3.4.14
|
166
|
+
signing_key:
|
152
167
|
specification_version: 4
|
153
168
|
summary: Implements a Period class as a Range of Dates.
|
154
169
|
test_files: []
|