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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6265d2bbcfe0ee522067acb075b37f2c7ce1816e
4
- data.tar.gz: 7cf60313a4f3c6bffadaf34323c4a1062c94b0f7
3
+ metadata.gz: f129c833ebff73231353110dd8c50fa422eb58f3
4
+ data.tar.gz: a19d2bdd83e040c1ca84553f6172ebb03e56d856
5
5
  SHA512:
6
- metadata.gz: ee91782de7b7d4d88c908b28bc8d751536ebf7b4e4c13784e8bfdbe55134f818d66b4b4d4eb2a1b98deee2d8a1b3e16658926bf608c962a4aadf52e84ea2b827
7
- data.tar.gz: 7f4bdba721092863f11cdc7239c4ef58fc019a11c63acef78356d159dc578c3889dcca9850c5bece7acd4665e4dbe3ce2345637c56ce6bc6dbddeb3c0b8b2ed9
6
+ metadata.gz: 990d55b6ab2802c6a39f372221ee0cc382e9b4bd583246c296008569982886d7ab0fd230696d18a3a829159e18c8fb2a7d41691e0c72575e780b77627be03817
7
+ data.tar.gz: 6ab08c520c375249c17addca5c74039c244ac75fe53128faac21135f3f13014780de403abb165db6fa6c0c89c1f7a37e1a2012152673ca0da9aa1d2951b5728b
@@ -0,0 +1,4 @@
1
+ 2014-09-04 Daniel E. Doherty <ded-law@ddoherty.net>
2
+
3
+ * range.rb (Range#left_contiguous, Range#overlaps): test overlap
4
+ for both orders of arguments (self, other) and (other, self).
@@ -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
 
@@ -50,7 +50,8 @@ class Range
50
50
  end
51
51
 
52
52
  def overlaps?(other)
53
- cover?(other.min) || cover?(other.max)
53
+ (cover?(other.min) || cover?(other.max) ||
54
+ other.cover?(min) || other.cover?(max))
54
55
  end
55
56
 
56
57
  def intersection(other)
@@ -1,3 +1,7 @@
1
1
  module FatCore
2
- VERSION = "0.1.1"
2
+ MAJOR = 0
3
+ MINOR = 1
4
+ PATCH = 2
5
+
6
+ VERSION = [MAJOR, MINOR, PATCH].compact.join('.')
3
7
  end
@@ -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(Date.parse('2013-01-01'), Date.parse('2013-12-13'))).
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.first).to eq(pp.first)
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')
@@ -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
- end
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.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-08-21 00:00:00.000000000 Z
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