quarter 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -0
- data/lib/quarter.rb +51 -0
- data/quarter.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43375d0c4b1028806f1a4e065d6da6b910b23e354377270125ac8953c629b15d
|
4
|
+
data.tar.gz: b40a713d14c5b278fe823571413117e7da417734d19fb5e522f6829e34a2ab79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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])
|
data/lib/quarter.rb
CHANGED
@@ -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
|
data/quarter.gemspec
CHANGED
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.
|
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-
|
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.
|
48
|
+
rubygems_version: 3.1.4
|
49
49
|
signing_key:
|
50
50
|
specification_version: 4
|
51
51
|
summary: See description
|