range_compressor 1.1.1 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 76bb69e9cee7120d43ba333dca4ae67b699eba91893bc963b9bb6d904eec57aa
4
- data.tar.gz: a32ac8091770ede579ae03238a1774b370609bff5521875a7aca19cdfd1c0ab2
3
+ metadata.gz: 31e9cdfc716d5a8d19654cd30d69540aaacb5f0b98372cf39de878d0a0b2f33e
4
+ data.tar.gz: b2b0d7803f967cccda9a729f40e825ff640c300edfbbb93a9824c6166c323750
5
5
  SHA512:
6
- metadata.gz: fce2b59dad8f9a70ea85000dae4cb64cee60baafa27751b063107deba93d06636d564ca61fd14bcd3c8fbbdfead982c839dfbf84d46564ce1e36a7fcd41860ad
7
- data.tar.gz: cd1f5fb41e3d0b014b10b3f31a3482ebbff5179736c284bfb0e7fe408e614375df2a1931e1d145ee2879bdcd68030537140877e93a765318de91b7b4ecc85ce4
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
@@ -1,3 +1,3 @@
1
1
  module RangeCompressor
2
- VERSION = '1.1.1'
2
+ VERSION = '1.2.0'
3
3
  end
@@ -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.any? { |anc| SORTED_SET_CLASSES.include? anc.to_s }
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
- each_flattened(arg) { |el| hash[el] = true }
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 each_flattened(arg, &block)
55
- if arg.class == Range && (arg.begin.nil? || arg.end.nil?)
56
- raise ArgumentError, 'beginless and endless Ranges are not supported'
57
- elsif arg.respond_to?(:each)
58
- arg.each { |el| each_flattened(el, &block) }
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
- block.call(arg)
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.1.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-08 00:00:00.000000000 Z
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.3.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.