range_compressor 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/range_compressor/version.rb +1 -1
- data/lib/range_compressor.rb +10 -8
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31e9cdfc716d5a8d19654cd30d69540aaacb5f0b98372cf39de878d0a0b2f33e
|
4
|
+
data.tar.gz: b2b0d7803f967cccda9a729f40e825ff640c300edfbbb93a9824c6166c323750
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 508c545f44479bd9c3365385acfd92a26fcb77cea09bbe57145580e3e8bb603706cdd4907091ab1eeffc42f5c5de572cd8a7913aabac03e91dcfc90af52edd84
|
7
|
+
data.tar.gz: 3f829b5a3c82158c5b88534646be0327ef306270bd7e5687630aa1dd1760a28762bcb8d30cd417250f71678623f8e3964b5c6274aaaf1d3484fb1eb299eb3960
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## [1.2.0]
|
8
|
+
|
9
|
+
### Added
|
10
|
+
|
11
|
+
- improved performance
|
12
|
+
|
7
13
|
## [1.1.1]
|
8
14
|
|
9
15
|
### Fixed
|
data/lib/range_compressor.rb
CHANGED
@@ -4,6 +4,7 @@ module RangeCompressor
|
|
4
4
|
module_function
|
5
5
|
|
6
6
|
def compress(arg)
|
7
|
+
# make contents flat, unique, and sorted
|
7
8
|
sorted_set = to_sorted_set(arg)
|
8
9
|
|
9
10
|
ranges = []
|
@@ -40,24 +41,25 @@ module RangeCompressor
|
|
40
41
|
def to_sorted_set(arg)
|
41
42
|
if arg.nil?
|
42
43
|
[]
|
43
|
-
elsif arg.class.ancestors.
|
44
|
+
elsif (arg.class.ancestors.map(&:to_s) & SORTED_SET_CLASSES).any?
|
44
45
|
arg
|
45
46
|
elsif arg.respond_to?(:each)
|
46
47
|
hash = {}
|
47
|
-
|
48
|
+
flatten(arg, hash)
|
48
49
|
hash.keys.sort
|
49
50
|
else
|
50
51
|
raise(ArgumentError, 'value must be enumerable')
|
51
52
|
end
|
52
53
|
end
|
53
54
|
|
54
|
-
def
|
55
|
-
if arg.
|
56
|
-
|
57
|
-
|
58
|
-
|
55
|
+
def flatten(arg, hash)
|
56
|
+
if arg.respond_to?(:each)
|
57
|
+
if arg.instance_of?(Range) && (arg.begin.nil? || arg.end.nil?)
|
58
|
+
raise ArgumentError, 'beginless and endless Ranges are not supported'
|
59
|
+
end
|
60
|
+
arg.each { |el| flatten(el, hash) }
|
59
61
|
else
|
60
|
-
|
62
|
+
hash[arg] = true
|
61
63
|
end
|
62
64
|
end
|
63
65
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: range_compressor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Janosch Müller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-02
|
11
|
+
date: 2022-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -49,7 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
49
49
|
- !ruby/object:Gem::Version
|
50
50
|
version: '0'
|
51
51
|
requirements: []
|
52
|
-
rubygems_version: 3.
|
52
|
+
rubygems_version: 3.4.0.dev
|
53
53
|
signing_key:
|
54
54
|
specification_version: 4
|
55
55
|
summary: Compresses Arrays of Objects to Arrays of Ranges.
|