fat_core 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fat_core/period.rb +21 -0
- data/lib/fat_core/version.rb +1 -1
- data/spec/lib/period_spec.rb +27 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad4e7a10323401979aefdc84969be57785c44a0f
|
4
|
+
data.tar.gz: e8e0af09365623587773931ad78d78e6611f85e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd3d5625bd384cc287d7dc032f4f5f8da0593fb1fd9d8cdc16310ea2f53e1c86aaa18702f03bdf42f8f11abc7b7d8cfcb1277327aab08e8608b7f70dd8f3fc5b
|
7
|
+
data.tar.gz: 500eb2d655fe5be2be5931d2dfb382eebda77d33224b6edebc89bf6bce3ad610476f4297a44a0fdb25273424abd86cdb3af56c46dd937431e1add4ff862370c5
|
data/lib/fat_core/period.rb
CHANGED
@@ -52,6 +52,27 @@ class Period
|
|
52
52
|
TO_DATE = Period.new(Date::BOT, Date.current)
|
53
53
|
FOREVER = Period.new(Date::BOT, Date::EOT)
|
54
54
|
|
55
|
+
# Need custom setters to ensure first <= last
|
56
|
+
def first=(new_first)
|
57
|
+
unless new_first.kind_of?(Date)
|
58
|
+
raise ArgumentError, "can't set Period#first to non-date"
|
59
|
+
end
|
60
|
+
unless new_first <= last
|
61
|
+
raise ArgumentError, "cannot make Period#first > Period#last"
|
62
|
+
end
|
63
|
+
@first = new_first
|
64
|
+
end
|
65
|
+
|
66
|
+
def last=(new_last)
|
67
|
+
unless new_last.kind_of?(Date)
|
68
|
+
raise ArgumentError, "can't set Period#last to non-date"
|
69
|
+
end
|
70
|
+
unless new_last >= first
|
71
|
+
raise ArgumentError, "cannot make Period#last < Period#first"
|
72
|
+
end
|
73
|
+
@last = new_last
|
74
|
+
end
|
75
|
+
|
55
76
|
# Comparable base: periods are equal only if their first and last dates are
|
56
77
|
# equal. Sorting will be by first date, then last, so periods starting on
|
57
78
|
# the same date will sort by last date, thus, from smallest to largest in
|
data/lib/fat_core/version.rb
CHANGED
data/spec/lib/period_spec.rb
CHANGED
@@ -127,6 +127,33 @@ describe Period do
|
|
127
127
|
end
|
128
128
|
|
129
129
|
describe "instance methods" do
|
130
|
+
|
131
|
+
it "should be able to set first" do
|
132
|
+
pp = Period.new('2014-12-07', '2014-12-17')
|
133
|
+
pp.first = Date.parse('2014-12-01')
|
134
|
+
expect(pp.first).to eq Date.parse('2014-12-01')
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should be able to set last" do
|
138
|
+
pp = Period.new('2014-12-07', '2014-12-17')
|
139
|
+
pp.last = Date.parse('2014-12-31')
|
140
|
+
expect(pp.last).to eq Date.parse('2014-12-31')
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should not be able to set first > last" do
|
144
|
+
pp = Period.new('2014-12-07', '2014-12-17')
|
145
|
+
expect {
|
146
|
+
pp.first = Date.parse('2014-12-31')
|
147
|
+
}.to raise_error ArgumentError
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should not be able to set last < first" do
|
151
|
+
pp = Period.new('2014-12-07', '2014-12-17')
|
152
|
+
expect {
|
153
|
+
pp.last = Date.parse('2014-12-01')
|
154
|
+
}.to raise_error ArgumentError
|
155
|
+
end
|
156
|
+
|
130
157
|
it "should be able to compare for equality" do
|
131
158
|
pp1 = Period.new('2013-01-01', '2013-12-31')
|
132
159
|
pp2 = Period.new('2013-01-01', '2013-12-31')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fat_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
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: 2014-12-
|
11
|
+
date: 2014-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simplecov
|