range_compressor 1.0.0
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.
- checksums.yaml +7 -0
- data/.gitignore +31 -0
- data/.rspec +3 -0
- data/.travis.yml +8 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +26 -0
- data/Rakefile +6 -0
- data/bin/console +7 -0
- data/bin/setup +8 -0
- data/lib/range_compressor.rb +43 -0
- data/lib/range_compressor/version.rb +3 -0
- data/range_compressor.gemspec +25 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 83e62be00199f227f3dae78b086d5f63759205cfa19c5eeb255bf5787b33450b
|
4
|
+
data.tar.gz: f62233009ec12d166fb2072897e8ecc95336ec6df6745facaa7b7cb530d9c2f7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4ca724e589d5827ce79c89556acf4b97d8984f65d8c417f66b227a64b82d5e8b1aa3e20d372818214146ef750d8f445ac731136d1cbc1862de7c3152b29af1a7
|
7
|
+
data.tar.gz: 178feded786fb56dbcd52574a4dca4cae421ef96f37318d3c778206d83849aa9b1d221fb91750c466945eb05fe21342ad381322e3656a8b427a8831f7c11998e
|
data/.gitignore
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
*.bundle
|
2
|
+
*.gem
|
3
|
+
*.iml
|
4
|
+
*.stTheme.cache
|
5
|
+
*.sublime-project
|
6
|
+
*.sublime-workspace
|
7
|
+
*.swp
|
8
|
+
*.tmlanguage.cache
|
9
|
+
*.tmPreferences.cache
|
10
|
+
*~
|
11
|
+
.byebug_history
|
12
|
+
.DS_Store
|
13
|
+
.idea/
|
14
|
+
.ruby-gemset
|
15
|
+
.ruby-version
|
16
|
+
.tags
|
17
|
+
.tags1
|
18
|
+
bbin/
|
19
|
+
binstubs/*
|
20
|
+
bundler_stubs/*/.yardoc
|
21
|
+
Gemfile.lock
|
22
|
+
/.bundle/
|
23
|
+
/_yardoc/
|
24
|
+
/coverage/
|
25
|
+
/doc/
|
26
|
+
/pkg/
|
27
|
+
/spec/reports/
|
28
|
+
/tmp/
|
29
|
+
|
30
|
+
# rspec failure tracking
|
31
|
+
.rspec_status
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Jannosch Müller
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# RangeCompressor
|
2
|
+
|
3
|
+
[](http://badge.fury.io/rb/range_compressor)
|
4
|
+
[](https://travis-ci.org/janosch-x/range_compressor)
|
5
|
+
|
6
|
+
A micro-gem that turns this:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
[1, 2, 3, 4, 6, 8, 9, 10]
|
10
|
+
```
|
11
|
+
|
12
|
+
into this:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
[1..4, 6..6, 8..10]
|
16
|
+
```
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
`gem install range_compressor`
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
ranges = RangeCompressor.compress(some_enumerable)
|
26
|
+
```
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'range_compressor/version'
|
2
|
+
|
3
|
+
module RangeCompressor
|
4
|
+
module_function
|
5
|
+
|
6
|
+
SORTED_SET_CLASSES = %w[
|
7
|
+
CharacterSet
|
8
|
+
CharacterSet::Pure
|
9
|
+
ImmutableSet
|
10
|
+
SortedSet
|
11
|
+
].freeze
|
12
|
+
|
13
|
+
# Set#divide is very slow unfortunately, else it would be nice for this:
|
14
|
+
# divide { |i, j| (i - j).abs == 1 }
|
15
|
+
def compress(enum)
|
16
|
+
if enum.class.ancestors.none? { |anc| SORTED_SET_CLASSES.include? anc.to_s }
|
17
|
+
require 'set'
|
18
|
+
enum = SortedSet.new(enum)
|
19
|
+
end
|
20
|
+
|
21
|
+
ranges = []
|
22
|
+
previous = nil
|
23
|
+
current_start = nil
|
24
|
+
current_end = nil
|
25
|
+
|
26
|
+
enum.each do |object|
|
27
|
+
if previous.nil?
|
28
|
+
current_start = object
|
29
|
+
elsif previous.next != object
|
30
|
+
# gap found, finalize previous range
|
31
|
+
ranges << (current_start..current_end)
|
32
|
+
current_start = object
|
33
|
+
end
|
34
|
+
current_end = object
|
35
|
+
previous = object
|
36
|
+
end
|
37
|
+
|
38
|
+
# add final range
|
39
|
+
ranges << (current_start..current_end) if current_start
|
40
|
+
|
41
|
+
ranges
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'range_compressor/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'range_compressor'
|
7
|
+
s.version = RangeCompressor::VERSION
|
8
|
+
s.authors = ['Janosch Müller']
|
9
|
+
s.email = ['janosch84@gmail.com']
|
10
|
+
|
11
|
+
s.summary = 'Compresses Arrays of Objects to Arrays of Ranges.'
|
12
|
+
s.homepage = 'https://github.com/janosch-x/range_compressor'
|
13
|
+
s.license = 'MIT'
|
14
|
+
|
15
|
+
s.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
s.require_paths = ['lib']
|
19
|
+
|
20
|
+
s.required_ruby_version = '>= 1.9.3'
|
21
|
+
|
22
|
+
s.add_development_dependency 'bundler', '~> 1.16'
|
23
|
+
s.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
s.add_development_dependency 'rspec', '~> 3.0'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: range_compressor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Janosch Müller
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-07-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- janosch84@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- lib/range_compressor.rb
|
72
|
+
- lib/range_compressor/version.rb
|
73
|
+
- range_compressor.gemspec
|
74
|
+
homepage: https://github.com/janosch-x/range_compressor
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 1.9.3
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.7.6
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Compresses Arrays of Objects to Arrays of Ranges.
|
98
|
+
test_files: []
|