fat_core 0.2.3 → 0.2.4
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 +7 -2
- data/lib/fat_core/version.rb +1 -1
- data/spec/lib/period_spec.rb +14 -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: 4226717355dd1d018a8b28fb655d36760ebc2afd
|
4
|
+
data.tar.gz: 69a9a6fba1a6268881fc8cb62b4e6bacb9bf481a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 484d04f6e77d04a10476ae3b3f8323eda4ba0f12d0378ad9f103461b6635c40285a3d6edbbead4f9b06cf06789111eaf929909ba4f870475e215755ac0d3f25c
|
7
|
+
data.tar.gz: 072820b9a27a82d34b708f7dabcc0e4537008edb278f624b49d5b202fd8cc2ebcd32e6aae036e5ed9d772e58e1199a2f741d3c3bcd58524e2cd884b90e9d3f55
|
data/lib/fat_core/period.rb
CHANGED
@@ -4,7 +4,7 @@ class Period
|
|
4
4
|
include Enumerable
|
5
5
|
include Comparable
|
6
6
|
|
7
|
-
|
7
|
+
attr_reader :first, :last
|
8
8
|
|
9
9
|
def initialize(first, last)
|
10
10
|
case first
|
@@ -273,9 +273,14 @@ class Period
|
|
273
273
|
|
274
274
|
def intersection(other)
|
275
275
|
result = self.to_range.intersection(other.to_range)
|
276
|
-
|
276
|
+
if result.nil?
|
277
|
+
nil
|
278
|
+
else
|
279
|
+
Period.new(result.first, result.last)
|
280
|
+
end
|
277
281
|
end
|
278
282
|
alias_method :&, :intersection
|
283
|
+
alias_method :narrow_to, :intersection
|
279
284
|
|
280
285
|
def union(other)
|
281
286
|
result = self.to_range.union(other.to_range)
|
data/lib/fat_core/version.rb
CHANGED
data/spec/lib/period_spec.rb
CHANGED
@@ -462,6 +462,20 @@ describe Period do
|
|
462
462
|
expect((month & year).class).to eq(Period)
|
463
463
|
end
|
464
464
|
|
465
|
+
it "should alias narrow_to to intersection" do
|
466
|
+
period1 = Period.parse_spec('2014')
|
467
|
+
period2 = Period.new('2014-06-01', '2015-02-28')
|
468
|
+
period3 = period1.narrow_to(period2)
|
469
|
+
expect(period3.first).to eq(period2.first)
|
470
|
+
expect(period3.last).to eq(period1.last)
|
471
|
+
end
|
472
|
+
|
473
|
+
it "should return nil if no intersection" do
|
474
|
+
year = Period.parse_spec('2014')
|
475
|
+
month = Period.parse_spec('2013-05')
|
476
|
+
expect(year & month).to be_nil
|
477
|
+
end
|
478
|
+
|
465
479
|
it "should know its union with other period" do
|
466
480
|
last_month = Period.parse_spec('last_month')
|
467
481
|
month = Period.parse_spec('this_month')
|
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.4
|
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:
|
11
|
+
date: 2015-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simplecov
|