range_utils 1.0.0 → 1.1.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: e1af9e6d4733a5b64c0f6f44036636c215b1708f
4
- data.tar.gz: 7c74535167ad2a1ab35b63dff3c27dc4c9112a31
3
+ metadata.gz: 3c29b94d801585958a9838998e968c88685af5c2
4
+ data.tar.gz: 0f2df5d19f9a96541ec539af239424a4ad147ce4
5
5
  SHA512:
6
- metadata.gz: 84ee08a6267adbf7e1922e172ed0e12648f3a816255f410162fae6fa31dc9b4eba82568618bb73b7c76b444a3604cca4014e360c5791c41a6e50f70039e2c6bb
7
- data.tar.gz: f2af9fa0b3678920c1b1fa0315bc3e57871dc4c8b14ad6f0edf61901e6a16e2ec78b8bcf9ee6cf672397fa36a8e6374b58aef819a10a270aa532a60e5c0ac387
6
+ metadata.gz: bf6651003f4cc15e932f99f9744fa7a5c4e6050c54965ef914dd7edd116ea659fb9c4877b31952794f8d1210bfa95d299b7c307b91f17a3f0c5d880a7a4312da
7
+ data.tar.gz: 83f1e046df43c7e002e860ead4a3e79c5a28da97c8e4f8ab6483966daf56ce9f1c07f9c37f58e5a70b951da65f8ac504f1df7e44018de97af2a811c5a05c116b
data/README.md CHANGED
@@ -13,7 +13,12 @@ Combine consecutive Range objects:
13
13
 
14
14
  Get the range for a given size of the collection:
15
15
 
16
- RangeUtils.range_for_size(14) #=> 0..13
16
+ RangeUtils.range_for_size_of(14) #=> 0..13
17
+
18
+ or get the size from a Range:
19
+
20
+ RangeUtils.size_from_range(0..0) #=> 1
21
+ RangeUtils.size_from_range(12..123) #=> 112
17
22
 
18
23
  Get the Ranges of maximum size for a given number of elements:
19
24
 
data/Rakefile CHANGED
@@ -20,8 +20,8 @@ Jeweler::Tasks.new do |gem|
20
20
  gem.name = "range_utils"
21
21
  gem.homepage = "http://github.com/julik/range_utils"
22
22
  gem.license = "MIT"
23
- gem.summary = %Q{There is a whole range of things you can do with a Range}
24
- gem.description = %Q{Range splice, split and other niceties}
23
+ gem.description = %Q{There is a whole range of things you can do with a Range}
24
+ gem.summary = %Q{Range splice, split and other niceties}
25
25
  gem.email = "me@julik.nl"
26
26
  gem.authors = ["Julik Tarkhanov"]
27
27
  # dependencies defined in Gemfile
data/lib/range_utils.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module RangeUtils
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
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).
@@ -82,6 +82,16 @@ module RangeUtils
82
82
  end
83
83
  end
84
84
 
85
+ # Returns the number of members of the given Range.
86
+ # size_from_range(0..0) #=> 1
87
+ # size_from_range(12..123) #=> 112
88
+ # Range members must support aruthmetic with integers.
89
+ def size_from_range(range)
90
+ size = range.end - range.begin + 1
91
+ raise ArgumentError, "The resulting size for range #{range} is negative" if size < 0
92
+ size
93
+ end
94
+
85
95
  alias_method :http_ranges_for_size, :ranges_of_offfsets_for_size
86
96
  extend self
87
97
  end
@@ -0,0 +1,59 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: range_utils 1.1.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "range_utils"
9
+ s.version = "1.1.0"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
13
+ s.authors = ["Julik Tarkhanov"]
14
+ s.date = "2015-06-10"
15
+ s.description = "There is a whole range of things you can do with a Range"
16
+ s.email = "me@julik.nl"
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".rspec",
24
+ ".travis.yml",
25
+ "Gemfile",
26
+ "LICENSE.txt",
27
+ "README.md",
28
+ "Rakefile",
29
+ "lib/range_utils.rb",
30
+ "range_utils.gemspec",
31
+ "spec/range_utils_spec.rb"
32
+ ]
33
+ s.homepage = "http://github.com/julik/range_utils"
34
+ s.licenses = ["MIT"]
35
+ s.rubygems_version = "2.2.2"
36
+ s.summary = "Range splice, split and other niceties"
37
+
38
+ if s.respond_to? :specification_version then
39
+ s.specification_version = 4
40
+
41
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
42
+ s.add_development_dependency(%q<rspec>, ["~> 3.0"])
43
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
44
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
45
+ s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
46
+ else
47
+ s.add_dependency(%q<rspec>, ["~> 3.0"])
48
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
49
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
50
+ s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
51
+ end
52
+ else
53
+ s.add_dependency(%q<rspec>, ["~> 3.0"])
54
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
55
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
56
+ s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
57
+ end
58
+ end
59
+
@@ -122,4 +122,17 @@ describe "RangeUtils" do
122
122
  expect(subject.http_ranges_for_size(785, 324)).to eq([0..323, 324..647, 648..784])
123
123
  end
124
124
  end
125
+
126
+ context '.size_from_range' do
127
+ it 'raises an ArgumentError when the range goes into negative' do
128
+ expect{
129
+ subject.size_from_range(0..-15)
130
+ }.to raise_error(ArgumentError, 'The resulting size for range 0..-15 is negative')
131
+ end
132
+
133
+ it 'computes the right size from the given Range' do
134
+ expect(subject.size_from_range(0..522753)).to eq(522754)
135
+ end
136
+ end
137
+
125
138
  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.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julik Tarkhanov
@@ -66,7 +66,7 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 2.0.1
69
- description: Range splice, split and other niceties
69
+ description: There is a whole range of things you can do with a Range
70
70
  email: me@julik.nl
71
71
  executables: []
72
72
  extensions: []
@@ -82,6 +82,7 @@ files:
82
82
  - README.md
83
83
  - Rakefile
84
84
  - lib/range_utils.rb
85
+ - range_utils.gemspec
85
86
  - spec/range_utils_spec.rb
86
87
  homepage: http://github.com/julik/range_utils
87
88
  licenses:
@@ -106,5 +107,5 @@ rubyforge_project:
106
107
  rubygems_version: 2.2.2
107
108
  signing_key:
108
109
  specification_version: 4
109
- summary: There is a whole range of things you can do with a Range
110
+ summary: Range splice, split and other niceties
110
111
  test_files: []