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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad4e7a10323401979aefdc84969be57785c44a0f
4
- data.tar.gz: e8e0af09365623587773931ad78d78e6611f85e8
3
+ metadata.gz: 4226717355dd1d018a8b28fb655d36760ebc2afd
4
+ data.tar.gz: 69a9a6fba1a6268881fc8cb62b4e6bacb9bf481a
5
5
  SHA512:
6
- metadata.gz: dd3d5625bd384cc287d7dc032f4f5f8da0593fb1fd9d8cdc16310ea2f53e1c86aaa18702f03bdf42f8f11abc7b7d8cfcb1277327aab08e8608b7f70dd8f3fc5b
7
- data.tar.gz: 500eb2d655fe5be2be5931d2dfb382eebda77d33224b6edebc89bf6bce3ad610476f4297a44a0fdb25273424abd86cdb3af56c46dd937431e1add4ff862370c5
6
+ metadata.gz: 484d04f6e77d04a10476ae3b3f8323eda4ba0f12d0378ad9f103461b6635c40285a3d6edbbead4f9b06cf06789111eaf929909ba4f870475e215755ac0d3f25c
7
+ data.tar.gz: 072820b9a27a82d34b708f7dabcc0e4537008edb278f624b49d5b202fd8cc2ebcd32e6aae036e5ed9d772e58e1199a2f741d3c3bcd58524e2cd884b90e9d3f55
@@ -4,7 +4,7 @@ class Period
4
4
  include Enumerable
5
5
  include Comparable
6
6
 
7
- attr_accessor :first, :last
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
- Period.new(result.first, result.last)
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)
@@ -1,7 +1,7 @@
1
1
  module FatCore
2
2
  MAJOR = 0
3
3
  MINOR = 2
4
- PATCH = 3
4
+ PATCH = 4
5
5
 
6
6
  VERSION = [MAJOR, MINOR, PATCH].compact.join('.')
7
7
  end
@@ -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.3
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: 2014-12-17 00:00:00.000000000 Z
11
+ date: 2015-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simplecov