range_utils 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,8 +3,7 @@ rvm:
3
3
  - 1.9.2
4
4
  - 1.9.3
5
5
  - 2.0.0
6
- - 2.1.1
7
- - 2.1.2
8
- - jruby
9
- cache: bundler
10
- sudo: false
6
+ - 2.1.5
7
+ - 2.2.2
8
+ sudo: false
9
+ cache: bundler
data/Gemfile CHANGED
@@ -6,5 +6,5 @@ group :development do
6
6
  gem "rspec", "~> 3.0"
7
7
  gem "rdoc", "~> 3.12"
8
8
  gem "bundler", "~> 1.0"
9
- gem "jeweler", "~> 2.0.1"
9
+ gem "jeweler", "1.8.4"
10
10
  end
data/README.md CHANGED
@@ -1,36 +1,35 @@
1
1
  # range_utils
2
2
 
3
+ [![Build Status](https://travis-ci.org/julik/range_utils.svg?branch=master)](https://travis-ci.org/julik/range_utils)
4
+
3
5
  There is more to a Range than meets the eye. Or more to the eye than meets the Range. Or whatever.
4
- `RangeUtils` is a non-intrusive module for doing useful things to Range objects.
5
6
 
7
+ `RangeUtils` is a non-intrusive module for doing useful things to Range objects.
6
8
  It is mainly useful for working with batches of IDs and HTTP content ranges.
7
9
 
8
10
  ## Usage
9
11
 
10
- Combine consecutive Range objects:
11
-
12
+ # Combine consecutive Range objects:
12
13
  RangeUtils.splice([0..0, 0..4, 5..14, 16..20]) #=> [0..14, 16..20]
13
-
14
- Get the range for a given size of the collection:
15
-
14
+
15
+ # Get the range for a given size of the collection:
16
16
  RangeUtils.range_for_size_of(14) #=> 0..13
17
-
18
- or get the size from a Range:
19
-
17
+
18
+ # or get the size from a Range:
20
19
  RangeUtils.size_from_range(0..0) #=> 1
21
20
  RangeUtils.size_from_range(12..123) #=> 112
22
-
23
- Get the Ranges of maximum size for a given number of elements:
24
-
21
+
22
+ # Get the Ranges of maximum size for a given number of elements:
25
23
  RangeUtils.ranges_of_offfsets_for_size(3, 1) #=> [0..0, 1..1, 2..2]
26
-
27
- Split a large Range into smaller ranges of given maximum size:
28
-
24
+
25
+ # Split a large Range into smaller ranges of given maximum size:
29
26
  RangeUtils.split_range_into_subranges_of(0..7, 3) #=> [0..2, 3..5, 5..7]
30
-
31
- Prepare a number of HTTP Range headers (each request will be 1 byte):
32
-
27
+
28
+ # Prepare a number of HTTP Range headers (each request will be 1 byte):
33
29
  RangeUtils.http_ranges_for_size(3, 1) #=> [0..0, 1..1, 2..2]
30
+
31
+ # Take N items from the range
32
+ RangeUtils.take(4..514, 3) #=> [4..6, 7..514]
34
33
 
35
34
  ## Contributing to range_utils
36
35
 
@@ -1,5 +1,5 @@
1
1
  module RangeUtils
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.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).
@@ -92,6 +92,22 @@ module RangeUtils
92
92
  size
93
93
  end
94
94
 
95
+ # Take N items from the range, and return two Ranges
96
+ # the first being the range containing N items requested,
97
+ # and the other containing the remainder
98
+ # take(4..514, 3) #=> [4..6, 7..514]
99
+ # If the range is too small for the number of items requested, the range itself and +nil+ will
100
+ # be returned instead:
101
+ #
102
+ # take(4..514, 1024) #=> [4..514, nil]
103
+ #
104
+ # Range members and n_items must support aruthmetic with integers
105
+ def take(from_range, n_items)
106
+ end_at = from_range.begin + (n_items - 1)
107
+ return [from_range, nil] if end_at > from_range.end
108
+ [from_range.begin..end_at, end_at.succ..from_range.end]
109
+ end
110
+
95
111
  alias_method :http_ranges_for_size, :ranges_of_offfsets_for_size
96
112
  extend self
97
113
  end
@@ -2,16 +2,14 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: range_utils 1.1.0 ruby lib
6
5
 
7
6
  Gem::Specification.new do |s|
8
7
  s.name = "range_utils"
9
- s.version = "1.1.0"
8
+ s.version = "1.2.0"
10
9
 
11
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
- s.require_paths = ["lib"]
13
11
  s.authors = ["Julik Tarkhanov"]
14
- s.date = "2015-06-10"
12
+ s.date = "2015-08-25"
15
13
  s.description = "There is a whole range of things you can do with a Range"
16
14
  s.email = "me@julik.nl"
17
15
  s.extra_rdoc_files = [
@@ -32,28 +30,29 @@ Gem::Specification.new do |s|
32
30
  ]
33
31
  s.homepage = "http://github.com/julik/range_utils"
34
32
  s.licenses = ["MIT"]
35
- s.rubygems_version = "2.2.2"
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = "1.8.23.2"
36
35
  s.summary = "Range splice, split and other niceties"
37
36
 
38
37
  if s.respond_to? :specification_version then
39
- s.specification_version = 4
38
+ s.specification_version = 3
40
39
 
41
40
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
42
41
  s.add_development_dependency(%q<rspec>, ["~> 3.0"])
43
42
  s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
44
43
  s.add_development_dependency(%q<bundler>, ["~> 1.0"])
45
- s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
44
+ s.add_development_dependency(%q<jeweler>, ["= 1.8.4"])
46
45
  else
47
46
  s.add_dependency(%q<rspec>, ["~> 3.0"])
48
47
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
49
48
  s.add_dependency(%q<bundler>, ["~> 1.0"])
50
- s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
49
+ s.add_dependency(%q<jeweler>, ["= 1.8.4"])
51
50
  end
52
51
  else
53
52
  s.add_dependency(%q<rspec>, ["~> 3.0"])
54
53
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
55
54
  s.add_dependency(%q<bundler>, ["~> 1.0"])
56
- s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
55
+ s.add_dependency(%q<jeweler>, ["= 1.8.4"])
57
56
  end
58
57
  end
59
58
 
@@ -123,6 +123,22 @@ describe "RangeUtils" do
123
123
  end
124
124
  end
125
125
 
126
+ context '.take' do
127
+ it 'returns the first range and the remainder' do
128
+ first, remainder = subject.take(0..12, 3)
129
+ expect(subject.size_from_range(first)).to eq(3)
130
+ expect(first).to eq(0..2)
131
+ expect(remainder).to eq(3..12)
132
+ expect(subject.splice([first, remainder])).to eq([0..12])
133
+ end
134
+
135
+ it 'returns nil as the remainder if n_items exceeds the whole range' do
136
+ first, remainder = subject.take(0..12, 15)
137
+ expect(first).to eq(0..12)
138
+ expect(remainder).to be_nil
139
+ end
140
+ end
141
+
126
142
  context '.size_from_range' do
127
143
  it 'raises an ArgumentError when the range goes into negative' do
128
144
  expect{
metadata CHANGED
@@ -1,71 +1,80 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: range_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Julik Tarkhanov
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2015-06-10 00:00:00.000000000 Z
12
+ date: 2015-08-25 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rspec
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - "~>"
19
+ - - ~>
18
20
  - !ruby/object:Gem::Version
19
21
  version: '3.0'
20
22
  type: :development
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - "~>"
27
+ - - ~>
25
28
  - !ruby/object:Gem::Version
26
29
  version: '3.0'
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: rdoc
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
- - - "~>"
35
+ - - ~>
32
36
  - !ruby/object:Gem::Version
33
37
  version: '3.12'
34
38
  type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
- - - "~>"
43
+ - - ~>
39
44
  - !ruby/object:Gem::Version
40
45
  version: '3.12'
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: bundler
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
- - - "~>"
51
+ - - ~>
46
52
  - !ruby/object:Gem::Version
47
53
  version: '1.0'
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
- - - "~>"
59
+ - - ~>
53
60
  - !ruby/object:Gem::Version
54
61
  version: '1.0'
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: jeweler
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
- - - "~>"
67
+ - - '='
60
68
  - !ruby/object:Gem::Version
61
- version: 2.0.1
69
+ version: 1.8.4
62
70
  type: :development
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
- - - "~>"
75
+ - - '='
67
76
  - !ruby/object:Gem::Version
68
- version: 2.0.1
77
+ version: 1.8.4
69
78
  description: There is a whole range of things you can do with a Range
70
79
  email: me@julik.nl
71
80
  executables: []
@@ -74,9 +83,9 @@ extra_rdoc_files:
74
83
  - LICENSE.txt
75
84
  - README.md
76
85
  files:
77
- - ".document"
78
- - ".rspec"
79
- - ".travis.yml"
86
+ - .document
87
+ - .rspec
88
+ - .travis.yml
80
89
  - Gemfile
81
90
  - LICENSE.txt
82
91
  - README.md
@@ -87,25 +96,29 @@ files:
87
96
  homepage: http://github.com/julik/range_utils
88
97
  licenses:
89
98
  - MIT
90
- metadata: {}
91
99
  post_install_message:
92
100
  rdoc_options: []
93
101
  require_paths:
94
102
  - lib
95
103
  required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
96
105
  requirements:
97
- - - ">="
106
+ - - ! '>='
98
107
  - !ruby/object:Gem::Version
99
108
  version: '0'
109
+ segments:
110
+ - 0
111
+ hash: 3847094652455965733
100
112
  required_rubygems_version: !ruby/object:Gem::Requirement
113
+ none: false
101
114
  requirements:
102
- - - ">="
115
+ - - ! '>='
103
116
  - !ruby/object:Gem::Version
104
117
  version: '0'
105
118
  requirements: []
106
119
  rubyforge_project:
107
- rubygems_version: 2.2.2
120
+ rubygems_version: 1.8.23.2
108
121
  signing_key:
109
- specification_version: 4
122
+ specification_version: 3
110
123
  summary: Range splice, split and other niceties
111
124
  test_files: []
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 3c29b94d801585958a9838998e968c88685af5c2
4
- data.tar.gz: 0f2df5d19f9a96541ec539af239424a4ad147ce4
5
- SHA512:
6
- metadata.gz: bf6651003f4cc15e932f99f9744fa7a5c4e6050c54965ef914dd7edd116ea659fb9c4877b31952794f8d1210bfa95d299b7c307b91f17a3f0c5d880a7a4312da
7
- data.tar.gz: 83f1e046df43c7e002e860ead4a3e79c5a28da97c8e4f8ab6483966daf56ce9f1c07f9c37f58e5a70b951da65f8ac504f1df7e44018de97af2a811c5a05c116b