quarter 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +26 -0
  3. data/lib/quarter.rb +51 -0
  4. data/quarter.gemspec +1 -1
  5. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ec19889b55f7693482a78ca92e13d9dc143a52dd22c7d1c97752343b95d3f70
4
- data.tar.gz: 533c16ac28a0d94cc0f45cc760005661ab6f9c81edeec68195e277662103d6ba
3
+ metadata.gz: 43375d0c4b1028806f1a4e065d6da6b910b23e354377270125ac8953c629b15d
4
+ data.tar.gz: b40a713d14c5b278fe823571413117e7da417734d19fb5e522f6829e34a2ab79
5
5
  SHA512:
6
- metadata.gz: 1ca11ce100186dc98c1274293fe883009b17273100047a64f678a33099c93b04d50dcd7d34150ab848816f72b6f77dd82194a5320e74c4e889fe4cdc7819dd7d
7
- data.tar.gz: 85ac644ab0b7a8dea6d416adca67cc97e80f894b6e82a601ebb8b7dfed4522084cca3525de00a12007a1bd463e3a32f25427d72457d930e0556cdd881804360b
6
+ metadata.gz: d417b09e7c7aba1451fdbe4dd4c1c5672c5043622e8b076497e2c5af3d5e83aa7ec42efbbe36dd6a5a0dc04b91a8a02a4ac85c2d36145a80abae908db49212c8
7
+ data.tar.gz: 84932606227d90523473be6ee607b9c746211568b76e430f9b082c30270bb17931b5db6a10aa8cad5c03c15392b452b3b7e68de6338a3425c4adcbcc0841f1cd
data/README.md CHANGED
@@ -34,3 +34,29 @@ p quarter.name
34
34
  p quarter.to_s
35
35
  p quarter.iso8601
36
36
  ```
37
+
38
+ ### Quarter::Methods
39
+
40
+ Include the `Quarter::Methods` module for methods which can be used to get the quarter for a given year in a manner that resembles written english. For example:
41
+
42
+ include Quarter::Methods
43
+
44
+ q1 = Q1 2020
45
+
46
+ ### Quarter::Constants
47
+
48
+ Include the `Quarter::Constants` module for constants which can be used to get the quarter for a given year in a manner that resembles written english. For example:
49
+
50
+ include Quarter::Constants
51
+
52
+ q1 = Q1/2020
53
+
54
+ q2 = 2020-Q2
55
+
56
+ ### YAML integration
57
+
58
+ Require `quarter/yaml` for YAML integration which supports dumping and loading quarter objects to and from YAML as scalar values. For example:
59
+
60
+ require 'quarter/yaml'
61
+
62
+ puts YAML.dump([Quarter.now])
@@ -172,3 +172,54 @@ end
172
172
  def Quarter.now
173
173
  Quarter(Time.now)
174
174
  end
175
+
176
+ module Quarter::Methods
177
+ def Q1(year)
178
+ Quarter.new(year, 1)
179
+ end
180
+
181
+ def Q2(year)
182
+ Quarter.new(year, 2)
183
+ end
184
+
185
+ def Q3(year)
186
+ Quarter.new(year, 3)
187
+ end
188
+
189
+ def Q4(year)
190
+ Quarter.new(year, 4)
191
+ end
192
+ end
193
+
194
+ class Quarter::Constant
195
+ def initialize(number)
196
+ @number = number
197
+ end
198
+
199
+ def -(other)
200
+ raise ArgumentError unless other.kind_of?(Integer)
201
+
202
+ Quarter.new(other, @number)
203
+ end
204
+
205
+ def /(other)
206
+ raise ArgumentError unless other.kind_of?(Integer)
207
+
208
+ Quarter.new(other, @number)
209
+ end
210
+
211
+ def coerce(other)
212
+ unless other.kind_of?(Integer)
213
+ raise TypeError, "#{self.class} can't be coerced with #{other.class}"
214
+ end
215
+
216
+ return self, other
217
+ end
218
+ end
219
+
220
+ module Quarter::Constants
221
+ Q1 = Quarter::Constant.new(1)
222
+ Q2 = Quarter::Constant.new(2)
223
+ Q3 = Quarter::Constant.new(3)
224
+ Q4 = Quarter::Constant.new(4)
225
+ end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'quarter'
3
- s.version = '1.1.0'
3
+ s.version = '1.2.0'
4
4
  s.license = 'LGPL-3.0'
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.authors = ['Tim Craft']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quarter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Craft
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-23 00:00:00.000000000 Z
11
+ date: 2020-10-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby gem for working with standard calendar quarters
14
14
  email:
@@ -45,7 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
47
  requirements: []
48
- rubygems_version: 3.1.2
48
+ rubygems_version: 3.1.4
49
49
  signing_key:
50
50
  specification_version: 4
51
51
  summary: See description