multi_range 1.2.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +46 -0
- data/.gitignore +60 -60
- data/.rubocop.yml +1174 -1174
- data/CHANGELOG.md +19 -1
- data/CODE_OF_CONDUCT.md +49 -49
- data/LICENSE +21 -21
- data/README.md +238 -202
- data/Rakefile +10 -10
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/gemfiles/Gemfile +9 -9
- data/lib/multi_range.rb +236 -154
- data/lib/multi_range/version.rb +5 -5
- data/multi_range.gemspec +47 -43
- metadata +35 -9
- data/.travis.yml +0 -29
- data/gemfiles/ruby_1_8_7.gemfile +0 -10
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
## Change Log
|
2
2
|
|
3
|
+
### [v2.1.0](https://github.com/khiav223577/multi_range/compare/v2.0.0...v2.1.0) 2021/03/17
|
4
|
+
- [#24](https://github.com/khiav223577/multi_range/pull/24) Avoid empty sub ranges (@GerritSe)
|
5
|
+
- [#25](https://github.com/khiav223577/multi_range/pull/25) Do not publish code coverage for PRs from forks (@khiav223577)
|
6
|
+
- [#22](https://github.com/khiav223577/multi_range/pull/22) Migrating from Travis CI to GitHub Actions (@khiav223577)
|
7
|
+
- [#21](https://github.com/khiav223577/multi_range/pull/21) Fix: test files should not be included in coverage (@khiav223577)
|
8
|
+
|
9
|
+
### [v2.0.0](https://github.com/khiav223577/multi_range/compare/v1.3.0...v2.0.0) 2020/11/19
|
10
|
+
- [#19](https://github.com/khiav223577/multi_range/pull/19) Implement intersection (@chrisnankervis)
|
11
|
+
- [#20](https://github.com/khiav223577/multi_range/pull/20) Drop support for Ruby 1.8 and 1.9 (@khiav223577)
|
12
|
+
- [#17](https://github.com/khiav223577/multi_range/pull/17) Refactoring - increase MAINTAINABILITY (@khiav223577)
|
13
|
+
|
14
|
+
### [v1.3.0](https://github.com/khiav223577/multi_range/compare/v1.2.0...v1.3.0) 2020/10/20
|
15
|
+
- [#16](https://github.com/khiav223577/multi_range/pull/16) Implement contain_overlaps? method (@khiav223577)
|
16
|
+
|
17
|
+
### [v1.2.0](https://github.com/khiav223577/multi_range/compare/v1.1.0...v1.2.0) 2020/10/16
|
18
|
+
- [#15](https://github.com/khiav223577/multi_range/pull/15) Add test cases to test union float ranges (@khiav223577)
|
19
|
+
- [#14](https://github.com/khiav223577/multi_range/pull/14) Support float ranges (@khiav223577)
|
20
|
+
|
3
21
|
### [v1.1.0](https://github.com/khiav223577/multi_range/compare/v1.0.0...v1.1.0) 2020/10/15
|
4
22
|
- [#13](https://github.com/khiav223577/multi_range/pull/13) Rename flatten => merge_overlaps (@khiav223577)
|
5
23
|
|
@@ -21,6 +39,6 @@
|
|
21
39
|
- [#4](https://github.com/khiav223577/multi_range/pull/4) Add each, map, index_with methods (@khiav223577)
|
22
40
|
- [#3](https://github.com/khiav223577/multi_range/pull/3) Support passing integer as range (@khiav223577)
|
23
41
|
|
24
|
-
###
|
42
|
+
### v0.0.1 2020/03/01
|
25
43
|
- [#2](https://github.com/khiav223577/multi_range/pull/2) Support Ruby 1.8.7 (@khiav223577)
|
26
44
|
- [#1](https://github.com/khiav223577/multi_range/pull/1) Implement MultiRange (@khiav223577)
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -1,49 +1,49 @@
|
|
1
|
-
# Contributor Code of Conduct
|
2
|
-
|
3
|
-
As contributors and maintainers of this project, and in the interest of
|
4
|
-
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
-
contribute through reporting issues, posting feature requests, updating
|
6
|
-
documentation, submitting pull requests or patches, and other activities.
|
7
|
-
|
8
|
-
We are committed to making participation in this project a harassment-free
|
9
|
-
experience for everyone, regardless of level of experience, gender, gender
|
10
|
-
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
-
body size, race, ethnicity, age, religion, or nationality.
|
12
|
-
|
13
|
-
Examples of unacceptable behavior by participants include:
|
14
|
-
|
15
|
-
* The use of sexualized language or imagery
|
16
|
-
* Personal attacks
|
17
|
-
* Trolling or insulting/derogatory comments
|
18
|
-
* Public or private harassment
|
19
|
-
* Publishing other's private information, such as physical or electronic
|
20
|
-
addresses, without explicit permission
|
21
|
-
* Other unethical or unprofessional conduct
|
22
|
-
|
23
|
-
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
-
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
-
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
-
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
-
threatening, offensive, or harmful.
|
28
|
-
|
29
|
-
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
-
fairly and consistently applying these principles to every aspect of managing
|
31
|
-
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
-
Conduct may be permanently removed from the project team.
|
33
|
-
|
34
|
-
This code of conduct applies both within project spaces and in public spaces
|
35
|
-
when an individual is representing the project or its community.
|
36
|
-
|
37
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
-
reported by contacting a project maintainer at mrtmrt15xn@yahoo.com.tw. All
|
39
|
-
complaints will be reviewed and investigated and will result in a response that
|
40
|
-
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
-
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
-
incident.
|
43
|
-
|
44
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
-
version 1.3.0, available at
|
46
|
-
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
-
|
48
|
-
[homepage]: http://contributor-covenant.org
|
49
|
-
[version]: http://contributor-covenant.org/version/1/3/0/
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at mrtmrt15xn@yahoo.com.tw. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/LICENSE
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2020 Rumble Huang
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
13
|
-
copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 Rumble Huang
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -1,202 +1,238 @@
|
|
1
|
-
# MultiRange
|
2
|
-
|
3
|
-
[![Gem Version](https://img.shields.io/gem/v/multi_range.svg?style=flat)](http://rubygems.org/gems/multi_range)
|
4
|
-
[![Build Status](https://
|
5
|
-
[![RubyGems](http://img.shields.io/gem/dt/multi_range.svg?style=flat)](http://rubygems.org/gems/multi_range)
|
6
|
-
[![Code Climate](https://codeclimate.com/github/khiav223577/multi_range/badges/gpa.svg)](https://codeclimate.com/github/khiav223577/multi_range)
|
7
|
-
[![Test Coverage](https://codeclimate.com/github/khiav223577/multi_range/badges/coverage.svg)](https://codeclimate.com/github/khiav223577/multi_range/coverage)
|
8
|
-
|
9
|
-
## Supports
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
```
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
```
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
multi_range = MultiRange.new([1
|
82
|
-
multi_range
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
multi_range
|
90
|
-
multi_range.
|
91
|
-
# =>
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
multi_range.
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
multi_range
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
```
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
MultiRange.new([1..
|
177
|
-
# => [2,
|
178
|
-
```
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
1
|
+
# MultiRange
|
2
|
+
|
3
|
+
[![Gem Version](https://img.shields.io/gem/v/multi_range.svg?style=flat)](http://rubygems.org/gems/multi_range)
|
4
|
+
[![Build Status](https://github.com/khiav223577/multi_range/workflows/Ruby/badge.svg)](https://github.com/khiav223577/multi_range/actions)
|
5
|
+
[![RubyGems](http://img.shields.io/gem/dt/multi_range.svg?style=flat)](http://rubygems.org/gems/multi_range)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/khiav223577/multi_range/badges/gpa.svg)](https://codeclimate.com/github/khiav223577/multi_range)
|
7
|
+
[![Test Coverage](https://codeclimate.com/github/khiav223577/multi_range/badges/coverage.svg)](https://codeclimate.com/github/khiav223577/multi_range/coverage)
|
8
|
+
|
9
|
+
## Supports
|
10
|
+
|
11
|
+
- Ruby 2.0 ~ 2.7
|
12
|
+
|
13
|
+
For Ruby 1.8.x and 1.9.x, please use multi_range < 2.
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'multi_range'
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install multi_range
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
Allow you to manipulate a group of ranges. Such as merging overlapping ranges, doing ranges union, intersection, difference, and so on.
|
32
|
+
|
33
|
+
### Sample a number
|
34
|
+
```rb
|
35
|
+
multi_range = MultiRange.new([1..5, 10..12])
|
36
|
+
multi_range.sample
|
37
|
+
# => equals to [1, 2, 3, 4, 5, 10, 11, 12].sample
|
38
|
+
```
|
39
|
+
|
40
|
+
### Difference of ranges
|
41
|
+
```rb
|
42
|
+
multi_range = MultiRange.new([1..10])
|
43
|
+
multi_range -= 5..7
|
44
|
+
multi_range.ranges
|
45
|
+
# => [1...5, 8..10]
|
46
|
+
```
|
47
|
+
|
48
|
+
```rb
|
49
|
+
multi_range = MultiRange.new([1..10, 50..70, 80..100])
|
50
|
+
multi_range -= 5..85
|
51
|
+
multi_range.ranges
|
52
|
+
# => [1...5, 86..100]
|
53
|
+
```
|
54
|
+
|
55
|
+
```rb
|
56
|
+
multi_range = MultiRange.new([1..10, 50..70, 80..100])
|
57
|
+
multi_range -= MultiRange.new([5..60, 75..85])
|
58
|
+
multi_range.ranges
|
59
|
+
# => [1...5, 61..70, 86..100]
|
60
|
+
```
|
61
|
+
|
62
|
+
### Union ranges
|
63
|
+
|
64
|
+
```rb
|
65
|
+
multi_range = MultiRange.new([1..5])
|
66
|
+
multi_range |= 3..8
|
67
|
+
multi_range.ranges
|
68
|
+
# => [1..8]
|
69
|
+
```
|
70
|
+
|
71
|
+
```rb
|
72
|
+
multi_range = MultiRange.new([1..5, 10..15, 20..25])
|
73
|
+
multi_range |= MultiRange.new([3..6, 14..22, 30])
|
74
|
+
multi_range.ranges
|
75
|
+
# => [1..6, 10..25, 30..30]
|
76
|
+
```
|
77
|
+
|
78
|
+
### Intersection ranges
|
79
|
+
|
80
|
+
```rb
|
81
|
+
multi_range = MultiRange.new([1..5])
|
82
|
+
multi_range &= 3..8
|
83
|
+
multi_range.ranges
|
84
|
+
# => [3..5]
|
85
|
+
```
|
86
|
+
|
87
|
+
```rb
|
88
|
+
multi_range = MultiRange.new([1..3, 5..10])
|
89
|
+
multi_range &= MultiRange.new([2..6, 8..9])
|
90
|
+
multi_range.ranges
|
91
|
+
# => [2..3, 5..6, 8..9]
|
92
|
+
```
|
93
|
+
|
94
|
+
### Merge overlaps
|
95
|
+
```rb
|
96
|
+
multi_range = MultiRange.new([1, 2, 4..6, 7, 8..12])
|
97
|
+
multi_range.merge_overlaps.ranges
|
98
|
+
# => [1..2, 4..12]
|
99
|
+
|
100
|
+
multi_range = MultiRange.new([1.2..1.5, 1.7..1.9, 1.8..2.2])
|
101
|
+
multi_range.merge_overlaps.ranges
|
102
|
+
# => [1.2..1.5, 1.7..2.2]
|
103
|
+
```
|
104
|
+
|
105
|
+
### Check if it overlaps with the other
|
106
|
+
|
107
|
+
```rb
|
108
|
+
multi_range = MultiRange.new([1..5, 10..15, 20..25])
|
109
|
+
multi_range.overlaps?(7..8)
|
110
|
+
# => false
|
111
|
+
|
112
|
+
multi_range.overlaps?(3..8)
|
113
|
+
# => true
|
114
|
+
|
115
|
+
multi_range.overlaps?(7..12)
|
116
|
+
# => true
|
117
|
+
```
|
118
|
+
|
119
|
+
```rb
|
120
|
+
multi_range = MultiRange.new([1..5, 10..15, 20..25])
|
121
|
+
multi_range.overlaps?(MultiRange.new([6..8, 18..22]))
|
122
|
+
# => true
|
123
|
+
```
|
124
|
+
|
125
|
+
|
126
|
+
### Check if it contains overlaps
|
127
|
+
|
128
|
+
```rb
|
129
|
+
MultiRange.new([0..3, 5..10, 20..50]).contain_overlaps?
|
130
|
+
# => false
|
131
|
+
|
132
|
+
MultiRange.new([0...5, 5..10, 20..50]).contain_overlaps?
|
133
|
+
# => false
|
134
|
+
|
135
|
+
MultiRange.new([0..5, 5..10, 20..50]).contain_overlaps?
|
136
|
+
# => true
|
137
|
+
|
138
|
+
MultiRange.new([0...7, 5..10, 20..50]).contain_overlaps?
|
139
|
+
# => true
|
140
|
+
```
|
141
|
+
|
142
|
+
### Range-like interface
|
143
|
+
|
144
|
+
#### each
|
145
|
+
```rb
|
146
|
+
MultiRange.new([1..3, 6, 8..9]).each{|s| print s }
|
147
|
+
# => 123689
|
148
|
+
```
|
149
|
+
|
150
|
+
#### map
|
151
|
+
```rb
|
152
|
+
MultiRange.new([1..3, 6, 8..9]).map{|s| s * 2 }
|
153
|
+
# => [2, 4, 6, 12, 16, 18]
|
154
|
+
```
|
155
|
+
|
156
|
+
#### index_with
|
157
|
+
```rb
|
158
|
+
MultiRange.new([1..3, 6, 8..9]).index_with(true)
|
159
|
+
# => { 1 => true, 2 => true, 3 => true, 6 => true, 8 => true, 9 => true }
|
160
|
+
```
|
161
|
+
|
162
|
+
#### min
|
163
|
+
```rb
|
164
|
+
MultiRange.new([1..3, 6, 8..9]).min
|
165
|
+
# => 1
|
166
|
+
```
|
167
|
+
|
168
|
+
#### max
|
169
|
+
```rb
|
170
|
+
MultiRange.new([1..3, 6, 8..9]).max
|
171
|
+
# => 9
|
172
|
+
```
|
173
|
+
|
174
|
+
#### to_a
|
175
|
+
```rb
|
176
|
+
MultiRange.new([1..3, 6, 8..9]).to_a
|
177
|
+
# => [1, 2, 3, 6, 8, 9]
|
178
|
+
```
|
179
|
+
|
180
|
+
|
181
|
+
#### size
|
182
|
+
```rb
|
183
|
+
MultiRange.new([1..3, 6, 8..9]).size
|
184
|
+
# => 6
|
185
|
+
```
|
186
|
+
|
187
|
+
### Warning
|
188
|
+
|
189
|
+
The return value may be different when there are some overlapped ranges.
|
190
|
+
Call `merge_overlaps` if you want to merge overlapped ranges.
|
191
|
+
|
192
|
+
```rb
|
193
|
+
MultiRange.new([1..5, 3..6]).to_a
|
194
|
+
# => [1, 2, 3, 4, 5, 3, 4, 5, 6]
|
195
|
+
|
196
|
+
MultiRange.new([1..5, 3..6]).merge_overlaps.to_a
|
197
|
+
# => [1, 2, 3, 4, 5, 6]
|
198
|
+
```
|
199
|
+
|
200
|
+
```rb
|
201
|
+
MultiRange.new([1..5, 3..6]).each{|s| print s }
|
202
|
+
# => 123453456
|
203
|
+
|
204
|
+
MultiRange.new([1..5, 3..6]).merge_overlaps.each{|s| print s }
|
205
|
+
# => 123456
|
206
|
+
```
|
207
|
+
|
208
|
+
```rb
|
209
|
+
MultiRange.new([1..5, 3..6]).map{|s| s * 2 }
|
210
|
+
# => [2, 4, 6, 8, 10, 6, 8, 10, 12]
|
211
|
+
|
212
|
+
MultiRange.new([1..5, 3..6]).merge_overlaps.map{|s| s * 2 }
|
213
|
+
# => [2, 4, 6, 8, 10, 12]
|
214
|
+
```
|
215
|
+
|
216
|
+
```rb
|
217
|
+
MultiRange.new([1..5, 3..6]).size
|
218
|
+
# => 9
|
219
|
+
|
220
|
+
MultiRange.new([1..5, 3..6]).merge_overlaps.size
|
221
|
+
# => 6
|
222
|
+
```
|
223
|
+
|
224
|
+
## Development
|
225
|
+
|
226
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
227
|
+
|
228
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
229
|
+
|
230
|
+
## Contributing
|
231
|
+
|
232
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/khiav223577/multi_range. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
233
|
+
|
234
|
+
|
235
|
+
## License
|
236
|
+
|
237
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
238
|
+
|