fat_period 1.3.1 → 1.4.0

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: a1b3b656730fd4a24f6ec1ae3c14a2828aee91a6ddf18ce8a4481e31e2d55ad3
4
- data.tar.gz: eb16ac79598e7c0054bac2ba57a9a5d8abce25cb8e810cbea9ac59ea4c8ead33
3
+ metadata.gz: 8592241a9f75949afa4df46469ff74029aa57ad67ac46234717aa751ba4cfef8
4
+ data.tar.gz: 26658db3f5a219236ae9bc9132cafa58850051fdf5d67c389c51306bcd4cd748
5
5
  SHA512:
6
- metadata.gz: 82b0fb1e076cf644da168edbfadfe44a060dc8ebdc43cdf450280a32466fc31a33aee79591a209d480cf192373cfcd8fe808f46e70e0c8186ff9fb10bdf84c66
7
- data.tar.gz: d1a151a0b003ba1bcaa54562928ab42075044ae04bbabca202001c56b1fd697779666c870541f023dddf64e248dd1a1ee2e5eeea5484e2c6f0ee392af469e874
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
@@ -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
 
@@ -31,9 +31,7 @@ class Period
31
31
  @last = Date.ensure_date(last).freeze
32
32
  freeze
33
33
 
34
- return unless @first > @last
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,7 +70,7 @@ class Period
72
70
 
73
71
  PHRASE_RE = %r{\A
74
72
  # One or both of from and to parts
75
- ((from\s+(?<from_part>[-_a-z0-9]+)\s*)?
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
@@ -1,3 +1,3 @@
1
1
  module FatPeriod
2
- VERSION = '1.3.1'.freeze
2
+ VERSION = '1.4.0'.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.3.1
4
+ version: 1.4.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: 2022-04-12 00:00:00.000000000 Z
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
@@ -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
@@ -147,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
162
  - !ruby/object:Gem::Version
148
163
  version: '0'
149
164
  requirements: []
150
- rubygems_version: 3.3.3
165
+ rubygems_version: 3.4.14
151
166
  signing_key:
152
167
  specification_version: 4
153
168
  summary: Implements a Period class as a Range of Dates.