fat_core 0.1.1 → 0.1.2
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/ChangeLog +4 -0
- data/lib/fat_core/period.rb +6 -0
- data/lib/fat_core/range.rb +2 -1
- data/lib/fat_core/version.rb +5 -1
- data/spec/lib/period_spec.rb +14 -2
- data/spec/lib/range_spec.rb +15 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f129c833ebff73231353110dd8c50fa422eb58f3
|
4
|
+
data.tar.gz: a19d2bdd83e040c1ca84553f6172ebb03e56d856
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 990d55b6ab2802c6a39f372221ee0cc382e9b4bd583246c296008569982886d7ab0fd230696d18a3a829159e18c8fb2a7d41691e0c72575e780b77627be03817
|
7
|
+
data.tar.gz: 6ab08c520c375249c17addca5c74039c244ac75fe53128faac21135f3f13014780de403abb165db6fa6c0c89c1f7a37e1a2012152673ca0da9aa1d2951b5728b
|
data/lib/fat_core/period.rb
CHANGED
@@ -314,6 +314,12 @@ class Period
|
|
314
314
|
end
|
315
315
|
|
316
316
|
def contains?(date)
|
317
|
+
if date.respond_to?(:to_date)
|
318
|
+
date = date.to_date
|
319
|
+
end
|
320
|
+
unless (date.is_a? Date)
|
321
|
+
raise ArgumentError, "argument must be a Date"
|
322
|
+
end
|
317
323
|
self.to_range.cover?(date)
|
318
324
|
end
|
319
325
|
|
data/lib/fat_core/range.rb
CHANGED
data/lib/fat_core/version.rb
CHANGED
data/spec/lib/period_spec.rb
CHANGED
@@ -15,7 +15,7 @@ describe Period do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should be initializable with Dates" do
|
18
|
-
expect(Period.new(
|
18
|
+
expect(Period.new('2013-01-01', '2013-12-13')).
|
19
19
|
to be_instance_of Period
|
20
20
|
end
|
21
21
|
|
@@ -101,7 +101,7 @@ describe Period do
|
|
101
101
|
rr = Period.new('2013-01-01', '2013-12-31').to_range
|
102
102
|
expect(rr).to be_instance_of Range
|
103
103
|
expect(rr.first).to eq(pp.first)
|
104
|
-
expect(rr.
|
104
|
+
expect(rr.last).to eq(pp.last)
|
105
105
|
end
|
106
106
|
|
107
107
|
it "should be able to tell if it contains a date" do
|
@@ -112,6 +112,18 @@ describe Period do
|
|
112
112
|
expect(pp.contains?(Date.parse('2012-07-04'))).to be false
|
113
113
|
end
|
114
114
|
|
115
|
+
it "should raise an error if contains? arg is not a date" do
|
116
|
+
pp = Period.new('2013-01-01', '2013-12-31')
|
117
|
+
expect {
|
118
|
+
pp.contains?(Period.new('2013-06-01', '2013-06-30'))
|
119
|
+
}.to raise_error(/must be a Date/)
|
120
|
+
|
121
|
+
# But not if argument can be converted to date with to_date
|
122
|
+
expect {
|
123
|
+
pp.contains?(Time.now)
|
124
|
+
}.not_to raise_error
|
125
|
+
end
|
126
|
+
|
115
127
|
it "should be able to make a concise period string" do
|
116
128
|
expect(Period.new('2013-01-01', '2013-12-31').to_s).to eq('2013')
|
117
129
|
expect(Period.new('2013-04-01', '2013-06-30').to_s).to eq('2013-2Q')
|
data/spec/lib/range_spec.rb
CHANGED
@@ -50,7 +50,7 @@ describe Range do
|
|
50
50
|
expect(((0..10) & (5..20))).to eq((5..10))
|
51
51
|
expect(((0..10) & (5..20))).to eq((5..20) & (0..10))
|
52
52
|
expect(((0..10) & (10..20))).to eq((10..10))
|
53
|
-
|
53
|
+
end
|
54
54
|
|
55
55
|
it "intersection should return nil if there is no overlap" do
|
56
56
|
expect(((0..10) & (15..20))).to be_nil
|
@@ -64,6 +64,7 @@ describe Range do
|
|
64
64
|
|
65
65
|
it "union should return nil if there is no overlap" do
|
66
66
|
expect(((0..10) & (15..20))).to be_nil
|
67
|
+
expect(((15..20) & (0..10))).to be_nil
|
67
68
|
end
|
68
69
|
|
69
70
|
it "should know the difference with another range" do
|
@@ -100,15 +101,20 @@ describe Range do
|
|
100
101
|
describe "joining" do
|
101
102
|
it "should be able to join contiguous ranges" do
|
102
103
|
expect((0..3).join(4..8)).to eq (0..8)
|
104
|
+
expect((4..8).join(0..3)).to eq (0..8)
|
103
105
|
end
|
104
106
|
|
105
107
|
it "should return nil on join of non-contiguous ranges" do
|
106
108
|
expect((0..3).join(5..8)).to be_nil
|
107
109
|
expect((0...3).join(4..8)).to be_nil
|
110
|
+
|
111
|
+
expect((5..8).join(0..3)).to be_nil
|
112
|
+
expect((4..8).join(0...3)).to be_nil
|
108
113
|
end
|
109
114
|
|
110
115
|
it "should work with Floats, allowing single-point overlap" do
|
111
116
|
expect((0.0..3.0).join(3.0..8.2)).to eq (0.0..8.2)
|
117
|
+
expect((3.0..8.2).join(0.0..3.0)).to eq (0.0..8.2)
|
112
118
|
end
|
113
119
|
end
|
114
120
|
|
@@ -144,6 +150,14 @@ describe Range do
|
|
144
150
|
expect((0..10).overlaps?(0..10)).to be_truthy
|
145
151
|
expect((0..10).overlaps?(11..12)).to be_falsy
|
146
152
|
expect((0..10).overlaps?(-11..-1)).to be_falsy
|
153
|
+
|
154
|
+
# Order of operands should not matter
|
155
|
+
expect((-3..5).overlaps?(0..10)).to be_truthy
|
156
|
+
expect((3..5).overlaps?(0..10)).to be_truthy
|
157
|
+
expect((8..15).overlaps?(0..10)).to be_truthy
|
158
|
+
expect((0..10).overlaps?(0..10)).to be_truthy
|
159
|
+
expect((11..12).overlaps?(0..10)).to be_falsy
|
160
|
+
expect((-11..-1).overlaps?(0..10)).to be_falsy
|
147
161
|
end
|
148
162
|
|
149
163
|
it "should be able to determine whether a set contains covered overlaps" do
|
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.1.
|
4
|
+
version: 0.1.2
|
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-
|
11
|
+
date: 2014-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -124,6 +124,7 @@ files:
|
|
124
124
|
- Rakefile
|
125
125
|
- fat_core.gemspec
|
126
126
|
- lib/fat_core.rb
|
127
|
+
- lib/fat_core/ChangeLog
|
127
128
|
- lib/fat_core/array.rb
|
128
129
|
- lib/fat_core/date.rb
|
129
130
|
- lib/fat_core/enumerable.rb
|