fat_core 0.2.2 → 0.2.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9fb47fa0fa82d7e1123e64ff79386a40ec64081
4
- data.tar.gz: 712a346af001436071a8429ddcadc772c3ecd31b
3
+ metadata.gz: ad4e7a10323401979aefdc84969be57785c44a0f
4
+ data.tar.gz: e8e0af09365623587773931ad78d78e6611f85e8
5
5
  SHA512:
6
- metadata.gz: e1825b694209cee54cd34fd6a3140875181fefde1e39744c3cc999d64ba9dfe0a85fa6b846f59ad80b49a8cf9a855b027969197a2c6e2256c421600a2537085d
7
- data.tar.gz: 645b35b380af7532e49001b58b627915a70c882ebc2f5aeae51c75eb6873113722d767b7e1fd5e4c4c64c723486411b69fa0fe5eb94c95c19afc8a02383ca7b7
6
+ metadata.gz: dd3d5625bd384cc287d7dc032f4f5f8da0593fb1fd9d8cdc16310ea2f53e1c86aaa18702f03bdf42f8f11abc7b7d8cfcb1277327aab08e8608b7f70dd8f3fc5b
7
+ data.tar.gz: 500eb2d655fe5be2be5931d2dfb382eebda77d33224b6edebc89bf6bce3ad610476f4297a44a0fdb25273424abd86cdb3af56c46dd937431e1add4ff862370c5
@@ -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
@@ -1,7 +1,7 @@
1
1
  module FatCore
2
2
  MAJOR = 0
3
3
  MINOR = 2
4
- PATCH = 2
4
+ PATCH = 3
5
5
 
6
6
  VERSION = [MAJOR, MINOR, PATCH].compact.join('.')
7
7
  end
@@ -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.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-12 00:00:00.000000000 Z
11
+ date: 2014-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simplecov