rangeset 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  class RangeSet
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/rangeset.rb CHANGED
@@ -1,8 +1,15 @@
1
+ lib_path = File.expand_path(File.join(File.dirname(__FILE__), '../lib'))
2
+ $:.unshift lib_path unless $:.any? { |path| path == lib_path }
3
+
1
4
  require "rangeset/version"
2
5
  require "rangeset/range"
3
6
 
4
7
  class RangeSet
5
8
  class << self
9
+ def [](*ranges)
10
+ build ranges
11
+ end
12
+
6
13
  def build(ranges)
7
14
  if ranges
8
15
  if ranges.is_a? Array
@@ -69,8 +76,8 @@ class RangeSet
69
76
  return [left, nil, nil] unless right
70
77
  return [nil, nil, right] unless left
71
78
  int = intersection(left, right)
72
- in_left = left.difference int
73
- in_right = right.difference int
79
+ in_left = difference left, int
80
+ in_right = difference right, int
74
81
  [in_left, int, in_right]
75
82
  end
76
83
  end
@@ -173,4 +180,8 @@ class RangeSet
173
180
  ranges == [other]
174
181
  end)
175
182
  end
183
+
184
+ def inspect
185
+ "RangeSet#{ ranges.inspect }"
186
+ end
176
187
  end
@@ -35,5 +35,16 @@ describe Range do
35
35
  subject.diff(other).should == [36..40, 30..35, 1..10]
36
36
  end
37
37
  end
38
+
39
+ context 'encompassing a RangeSet' do
40
+ subject { 0..8392 }
41
+ let(:other) { r = RangeSet[2089..2787, 2789..7266, 8371..8376, 8381..8382, 8384..8386, 8391..8392] }
42
+ it do
43
+ subject.diff(other).should == [
44
+ RangeSet[0..2088, 2788..2788, 7267..8370, 8377..8380, 8383..8383, 8387..8390],
45
+ RangeSet[2089..2787, 2789..7266, 8371..8376, 8381..8382, 8384..8386, 8391..8392],
46
+ nil]
47
+ end
48
+ end
38
49
  end
39
50
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rangeset
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1
5
+ version: 0.1.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Darrick Wiebe