range_utils 1.2.0 → 1.2.1
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.
- data/lib/range_utils.rb +2 -2
- data/range_utils.gemspec +1 -1
- data/spec/range_utils_spec.rb +6 -1
- metadata +2 -2
data/lib/range_utils.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module RangeUtils
|
2
|
-
VERSION = '1.2.
|
2
|
+
VERSION = '1.2.1'
|
3
3
|
|
4
4
|
# Tells whether the +item+ is included in the +range+, without enumerating
|
5
5
|
# through the +range+ (performing a quick bounds check).
|
@@ -104,7 +104,7 @@ module RangeUtils
|
|
104
104
|
# Range members and n_items must support aruthmetic with integers
|
105
105
|
def take(from_range, n_items)
|
106
106
|
end_at = from_range.begin + (n_items - 1)
|
107
|
-
return [from_range, nil] if end_at
|
107
|
+
return [from_range, nil] if end_at >= from_range.end
|
108
108
|
[from_range.begin..end_at, end_at.succ..from_range.end]
|
109
109
|
end
|
110
110
|
|
data/range_utils.gemspec
CHANGED
data/spec/range_utils_spec.rb
CHANGED
@@ -137,6 +137,12 @@ describe "RangeUtils" do
|
|
137
137
|
expect(first).to eq(0..12)
|
138
138
|
expect(remainder).to be_nil
|
139
139
|
end
|
140
|
+
|
141
|
+
it 'handles the 0-item remainder range case correctly' do
|
142
|
+
first, remainder = subject.take(0..1, 2)
|
143
|
+
expect(first).to eq(0..1)
|
144
|
+
expect(remainder).to be_nil
|
145
|
+
end
|
140
146
|
end
|
141
147
|
|
142
148
|
context '.size_from_range' do
|
@@ -150,5 +156,4 @@ describe "RangeUtils" do
|
|
150
156
|
expect(subject.size_from_range(0..522753)).to eq(522754)
|
151
157
|
end
|
152
158
|
end
|
153
|
-
|
154
159
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: range_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -108,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
108
108
|
version: '0'
|
109
109
|
segments:
|
110
110
|
- 0
|
111
|
-
hash:
|
111
|
+
hash: 4395321895595223882
|
112
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
113
|
none: false
|
114
114
|
requirements:
|