timerage 1.5.0 → 1.6.0

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: 9622b03dc29826d6fd62282884dc1de42fb7bd04
4
- data.tar.gz: 8c1c012b9584779d84822c8f6a2358f1a1daaeff
3
+ metadata.gz: 0ae2f36b387f927aad57a86abc300ed3465782a0
4
+ data.tar.gz: 8aa0c202c8cf41e5c1be6650c476a3b32a05a7f0
5
5
  SHA512:
6
- metadata.gz: b876dde86b6aa1542e29a80f46e59a9b24de9a7b72255ac5772e7ec1de61430001a76ad1874eaee071a0bcfe37dd85b838c392dc331c9b148948e420a6d63f7a
7
- data.tar.gz: 62bc60b3fb6b6e5c5e3d1234139ba5fc270856dfa824f643b22cb4c9b5e01aba0256e8e1150cb3776310312af06953f1a19aa4b6b0fbf6731e524aa5d47ae1e4
6
+ metadata.gz: 9f1762d865597b9f4c3604e8135bb2abb3bf4ce7cf6f75c7a4c0cfb02052044046394e6afaf57b919cb5e6c39a16620627556b7065607685878f5ce7ac5a704e
7
+ data.tar.gz: f144b3fbd7133e7194460e8a21a1bf1d4b47c9d3e3cbbecb4e376e556aa45c044fdb7b1164e14ebe6a52a21e242234345bcaff0e5607253a1354c7cf234bbe8a
@@ -23,6 +23,23 @@ module Timerage
23
23
  end
24
24
  end
25
25
 
26
+ def slice(seconds)
27
+ time_enumerator(seconds)
28
+ .map{|t|
29
+ end_time = [t+seconds, self.end].min
30
+ inclusive = (self.end == t && !exclude_end?) || t+seconds > self.end
31
+ TimeInterval.new(t, end_time, !inclusive) }
32
+ end
33
+
34
+ def ==(other)
35
+ self.begin == other.begin &&
36
+ self.end == other.end &&
37
+ self.exclude_end? == other.exclude_end?
38
+
39
+ rescue NoMethodError
40
+ false
41
+ end
42
+
26
43
  # Return new TimeInterval that is the concatenation of self and
27
44
  # other (if possible).
28
45
  #
@@ -44,7 +61,6 @@ module Timerage
44
61
  other.begin == self.end || other.end == self.begin
45
62
  end
46
63
 
47
-
48
64
  def cover?(time_or_interval)
49
65
  return super unless rangeish?(time_or_interval)
50
66
 
@@ -80,6 +96,15 @@ module Timerage
80
96
  self.begin <=> other.begin
81
97
  end
82
98
 
99
+ def ==(other)
100
+ self.begin == other.begin &&
101
+ self.end == other.end &&
102
+ self.exclude_end? == other.exclude_end?
103
+
104
+ rescue NoMethodError
105
+ false
106
+ end
107
+
83
108
  protected
84
109
 
85
110
  def rangeish?(an_obj)
@@ -1,3 +1,3 @@
1
1
  module Timerage
2
- VERSION = "1.5.0"
2
+ VERSION = "1.6.0"
3
3
  end
@@ -50,6 +50,11 @@ describe Timerage::TimeInterval do
50
50
  specify { expect(interval <=> (interval.end+1..interval.end+2)).to eq -1}
51
51
  specify { expect(interval <=> interval).to eq 0}
52
52
 
53
+ describe "==" do
54
+ specify { expect( described_class.new(interval) == interval ).to be true }
55
+ specify { expect( described_class.new(interval.begin, interval.end) == interval ).to be true }
56
+ end
57
+
53
58
  describe "+" do
54
59
  let(:adjacent_preceding_time_range) { interval.begin-42..interval.begin }
55
60
  let(:adjacent_following_time_range) { interval.end..interval.end+42 }
@@ -73,6 +78,22 @@ describe Timerage::TimeInterval do
73
78
  end
74
79
 
75
80
 
81
+ specify { expect(interval.cover? interval.begin+1..interval.end-1).to be_truthy }
82
+ specify { expect(interval.cover? interval.begin...interval.end).to be_truthy }
83
+ specify { expect(interval.cover? interval.begin-1..interval.end-1).to be_falsy }
84
+ specify { expect(interval.cover? interval.begin+1..interval.end+1).to be_falsy }
85
+
86
+ specify { expect(interval.overlap? interval.begin+1..interval.end-1).to be_truthy }
87
+ specify { expect(interval.overlap? interval.begin...interval.end).to be_truthy }
88
+ specify { expect(interval.overlap? interval.begin-1..interval.end-1).to be_truthy }
89
+ specify { expect(interval.overlap? interval.begin+1..interval.end+1).to be_truthy }
90
+ specify { expect(interval.overlap? interval.end+1..interval.end+2).to be_falsy }
91
+ specify { expect(interval.overlap? interval.begin-2..interval.begin-1).to be_falsy }
92
+
93
+ specify { expect(interval <=> (interval.begin-2..interval.begin-1)).to eq 1}
94
+ specify { expect(interval <=> (interval.end+1..interval.end+2)).to eq -1}
95
+ specify { expect(interval <=> interval).to eq 0}
96
+
76
97
  context "inclusive end" do
77
98
  specify { expect(interval.exclude_end?).to be false }
78
99
  specify { expect(interval.cover? now).to be true }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timerage
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Williams
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-04-13 00:00:00.000000000 Z
12
+ date: 2015-07-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  version: '0'
99
99
  requirements: []
100
100
  rubyforge_project:
101
- rubygems_version: 2.2.2
101
+ rubygems_version: 2.4.5
102
102
  signing_key:
103
103
  specification_version: 4
104
104
  summary: Simple refinement to Range to allow Time or Date as arguments