merginator 0.1.1 → 0.2.1

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: 1d2fea30ed75731053fb8a668dfde25de0b0bfa56b091020d68a0878dbc74ac4
4
- data.tar.gz: 478433d62ff8943e02dcb1affa790868d0d93bc45292c374c10fbc84e6bf44a5
3
+ metadata.gz: c8d45708d09006490c77f0d2819b0fecc13e35a2a81e69a6f4c7fcf5c8a8bf7f
4
+ data.tar.gz: c508d5dec15b52a26e3388130d9845a20b4821a1fb5f3f8c7acf735e48afc770
5
5
  SHA512:
6
- metadata.gz: 91709f61f93ae9b2296a935d06fdf69d6f8c8722ee91546d87329faa20a95e56be5b3d8fe4d62c6fcf8f7d55df41dfc5740d743a04097332d71cae1779f3e3f8
7
- data.tar.gz: 04004fb039e34a98ee2803f7d33da2d3654d280929299fd2121c11455992441183da5c6f55be3e8e51d5a9494e35158313ff9c57ed1a3231ef3af3b5971632c6
6
+ metadata.gz: c85058dd8a0282a43ce46050c4ddba76c9d7f7bb6a2997f2bdf06bf10646f1797e4f1f13a98bd1ec740449dd6501c8b5990255e19d8e5b08eba7e6bc68e0aa81
7
+ data.tar.gz: a4365f144da7520eecc9e18080aabe6cf16a3322778a5c08a7ff06832d6b85aa0e204629b667cd673d879f0244849da005b706e437897ddf266054c3bc92e13b
data/.rubocop.yml CHANGED
@@ -5,6 +5,9 @@ require:
5
5
  AllCops:
6
6
  TargetRubyVersion: 2.7.8
7
7
  NewCops: enable
8
+ Exclude:
9
+ - 'Steepfile'
10
+ - 'vendor/**/*'
8
11
 
9
12
  Style/StringLiterals:
10
13
  Enabled: true
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [0.2.1] - 2023-06-27
2
+
3
+ - Configuration change version bump
4
+
5
+ ## [0.2.0] - 2023-06-27
6
+
7
+ - Updating configuration
8
+ - Improving functionality based on usage
9
+
1
10
  ## [0.1.1] - 2023-06-26
2
11
 
3
12
  - Updating README
data/Gemfile CHANGED
@@ -8,8 +8,8 @@ gemspec
8
8
  gem 'rake'
9
9
 
10
10
  gem 'minitest'
11
-
12
- gem 'rubocop'
11
+ gem 'rubocop', require: false
13
12
  gem 'rubocop-minitest', require: false
14
13
  gem 'rubocop-rake', require: false
15
- gem 'rbs', require: false
14
+ gem 'simplecov', require: false
15
+ gem 'steep', require: false
data/Gemfile.lock CHANGED
@@ -1,13 +1,30 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- merginator (0.1.1)
4
+ merginator (0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ activesupport (7.0.5.1)
10
+ concurrent-ruby (~> 1.0, >= 1.0.2)
11
+ i18n (>= 1.6, < 2)
12
+ minitest (>= 5.1)
13
+ tzinfo (~> 2.0)
9
14
  ast (2.4.2)
15
+ concurrent-ruby (1.2.2)
16
+ csv (3.2.7)
17
+ docile (1.3.5)
18
+ ffi (1.15.5)
19
+ fileutils (1.7.1)
20
+ i18n (1.14.1)
21
+ concurrent-ruby (~> 1.0)
10
22
  json (2.6.3)
23
+ language_server-protocol (3.17.0.3)
24
+ listen (3.8.0)
25
+ rb-fsevent (~> 0.10, >= 0.10.3)
26
+ rb-inotify (~> 0.9, >= 0.9.10)
27
+ logger (1.5.3)
11
28
  minitest (5.18.1)
12
29
  parallel (1.23.0)
13
30
  parser (3.2.2.3)
@@ -16,11 +33,15 @@ GEM
16
33
  racc (1.7.1)
17
34
  rainbow (3.1.1)
18
35
  rake (13.0.6)
36
+ rb-fsevent (0.11.2)
37
+ rb-inotify (0.10.1)
38
+ ffi (~> 1.0)
19
39
  rbs (3.1.0)
20
40
  regexp_parser (2.8.1)
21
41
  rexml (3.2.5)
22
- rubocop (1.52.1)
42
+ rubocop (1.53.1)
23
43
  json (~> 2.3)
44
+ language_server-protocol (>= 3.17.0)
24
45
  parallel (~> 1.10)
25
46
  parser (>= 3.2.2.3)
26
47
  rainbow (>= 2.2.2, < 4.0)
@@ -36,6 +57,33 @@ GEM
36
57
  rubocop-rake (0.6.0)
37
58
  rubocop (~> 1.0)
38
59
  ruby-progressbar (1.13.0)
60
+ securerandom (0.2.2)
61
+ simplecov (0.21.2)
62
+ docile (~> 1.1)
63
+ simplecov-html (~> 0.11)
64
+ simplecov_json_formatter (~> 0.1)
65
+ simplecov-html (0.12.3)
66
+ simplecov_json_formatter (0.1.2)
67
+ steep (1.4.0)
68
+ activesupport (>= 5.1)
69
+ concurrent-ruby (>= 1.2.2)
70
+ csv (>= 3.0.9)
71
+ fileutils (>= 1.1.0)
72
+ json (>= 2.1.0)
73
+ language_server-protocol (>= 3.15, < 4.0)
74
+ listen (~> 3.0)
75
+ logger (>= 1.3.0)
76
+ parser (>= 3.1)
77
+ rainbow (>= 2.2.2, < 4.0)
78
+ rbs (>= 2.8.0)
79
+ securerandom (>= 0.1)
80
+ strscan (>= 1.0.0)
81
+ terminal-table (>= 2, < 4)
82
+ strscan (3.0.6)
83
+ terminal-table (3.0.2)
84
+ unicode-display_width (>= 1.1.1, < 3)
85
+ tzinfo (2.0.6)
86
+ concurrent-ruby (~> 1.0)
39
87
  unicode-display_width (2.4.2)
40
88
 
41
89
  PLATFORMS
@@ -45,10 +93,11 @@ DEPENDENCIES
45
93
  merginator!
46
94
  minitest
47
95
  rake
48
- rbs
49
96
  rubocop
50
97
  rubocop-minitest
51
98
  rubocop-rake
99
+ simplecov
100
+ steep
52
101
 
53
102
  BUNDLED WITH
54
103
  2.1.4
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Merginator
1
+ # Merginator [![Gem Version](https://badge.fury.io/rb/merginator.svg)](https://badge.fury.io/rb/merginator) ![Build Status](https://github.com/RyanVerhey/merginator/actions/workflows/main.yml/badge.svg?branch=main)
2
2
 
3
3
  Easily merge collections with a simple API!
4
4
 
@@ -6,11 +6,11 @@ Easily merge collections with a simple API!
6
6
 
7
7
  Install the gem and add to the application's Gemfile by executing:
8
8
 
9
- $ bundle add Merginator
9
+ $ bundle add merginator
10
10
 
11
11
  If bundler is not being used to manage dependencies, install the gem by executing:
12
12
 
13
- $ gem install Merginator
13
+ $ gem install merginator
14
14
 
15
15
  ## Usage
16
16
 
data/Rakefile CHANGED
@@ -13,4 +13,20 @@ require 'rubocop/rake_task'
13
13
 
14
14
  RuboCop::RakeTask.new
15
15
 
16
- task default: %i[test rubocop]
16
+ namespace :test do
17
+ desc 'Run all tests: tests, rubocop, and steep'
18
+ task :all do
19
+ Rake::Task['test'].execute
20
+ Rake::Task['rubocop'].execute
21
+ Rake::Task['test:steep:check'].execute
22
+ end
23
+
24
+ namespace :steep do
25
+ desc 'Run steep check'
26
+ task :check do
27
+ sh 'steep', 'check'
28
+ end
29
+ end
30
+ end
31
+
32
+ task default: %i[test rubocop test:steep:check]
data/Steepfile ADDED
@@ -0,0 +1,5 @@
1
+ target :merginator do
2
+ signature "sig"
3
+
4
+ check "lib"
5
+ end
@@ -7,33 +7,34 @@ module Merginator
7
7
  # first, 2 from the second, and one from the third. Also passing in the total,
8
8
  # or, an amount for a page
9
9
  class PatternMerge
10
- attr_reader :pattern, :total, :counts
10
+ attr_reader :pattern, :total, :counts, :wrapper
11
11
 
12
- def initialize(*pattern, total: nil)
12
+ def initialize(*pattern, total: nil, wrapper: [])
13
13
  @pattern = pattern
14
14
  validate_pattern
15
15
 
16
16
  @total = total
17
17
  validate_total
18
18
 
19
+ @wrapper = wrapper
20
+ validate_wrapper
21
+
19
22
  # Counts are helpful when you're looking for a particular length end result
20
23
  # and querying a database or index. If you're not, they're not needed.
21
- @counts = generate_pattern_counts(@total) if @total
24
+ @counts = generate_pattern_counts(@total)
22
25
  end
23
26
 
24
- def merge(*collections)
27
+ def merge(*collections, wrapper: @wrapper, ignore_total: false)
25
28
  validate_merge_collections(collections)
29
+ validate_wrapper wrapper
26
30
 
27
- total = @total || collections.sum(&:size)
31
+ total_to_use = @total
32
+ total_to_use = collections.sum(&:size) if !total || ignore_total
28
33
 
29
- slices_for_collections = collections.map.with_index do |collection, index|
30
- collection.each_slice(@pattern[index]).to_a
31
- end
34
+ slices_for_collections = slice_collections(collections)
35
+ merge_collections_into_wrapper(slices_for_collections, wrapper: wrapper, total: total_to_use)
32
36
 
33
- slices_for_collections.map(&:size).max.times.each_with_object([]) do |index, arr|
34
- arr << slices_for_collections.map { |slices| slices[index] || [] }.flatten
35
- break(arr) if arr.flatten.size >= total
36
- end.flatten.take(total)
37
+ wrapper
37
38
  end
38
39
 
39
40
  private
@@ -44,6 +45,8 @@ module Merginator
44
45
  # Merginator::Mergifier::PatternMerge.new(4, 2, 1, total: 25)
45
46
  # => [16, 6, 3]
46
47
  def generate_pattern_counts(total)
48
+ return unless total
49
+
47
50
  full_repetitions = total / @pattern.sum
48
51
  counts = @pattern.map { |num| num * full_repetitions }
49
52
 
@@ -57,13 +60,30 @@ module Merginator
57
60
  counts
58
61
  end
59
62
 
63
+ def slice_collections(collections)
64
+ collections.map.with_index do |collection, index|
65
+ collection.each_slice(@pattern[index]).to_a
66
+ end
67
+ end
68
+
69
+ def merge_collections_into_wrapper(slices_for_collections, wrapper:, total:)
70
+ slices_for_collections.map(&:size).max.to_i.times.each_with_object(wrapper) do |index, wrapper_obj|
71
+ wrapper_obj.concat slices_for_collections.map { |slices| slices[index] || [] }.flatten
72
+ break(wrapper_obj) if wrapper_obj.size >= total
73
+ end
74
+
75
+ wrapper.replace wrapper.take(total)
76
+ end
77
+
60
78
  def validate_pattern
61
79
  raise ArgumentError, 'there must be more than one collection in the pattern' if @pattern.count <= 1
62
80
  raise ArgumentError, 'pattern must be all integers' unless @pattern.all? { |n| n.is_a? Integer }
63
81
  end
64
82
 
65
83
  def validate_total
66
- raise ArgumentError, 'total must be at least 1' if @total && @total < 1
84
+ return if (@total || 1).positive?
85
+
86
+ raise ArgumentError, 'total must be at least 1'
67
87
  end
68
88
 
69
89
  def validate_merge_collections(collections)
@@ -73,11 +93,18 @@ module Merginator
73
93
  raise ArgumentError, message
74
94
  end
75
95
 
76
- if @total && collections.flatten.count < @total
77
- message = 'total number of elements in collections must be >= provided total; '
78
- message += "expected #{@total} elements, actual: #{collections.flatten.count}"
79
- raise ArgumentError, message
80
- end
96
+ total_to_use = @total || collections.flatten.count
97
+ return if collections.flatten.count >= total_to_use
98
+
99
+ message = 'total number of elements in collections must be >= provided total; '
100
+ message += "expected #{@total} elements, actual: #{collections.flatten.count}"
101
+ raise ArgumentError, message
102
+ end
103
+
104
+ def validate_wrapper(wrapper = @wrapper)
105
+ return if wrapper.is_a?(Array)
106
+
107
+ raise ArgumentError, 'wrapper must be like an array'
81
108
  end
82
109
  end
83
110
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Merginator
4
- VERSION = '0.1.1'
4
+ VERSION = '0.2.1'
5
5
  end
data/lib/merginator.rb CHANGED
@@ -5,8 +5,6 @@ require_relative 'merginator/pattern_merge'
5
5
 
6
6
  # Contains top-level namespace code
7
7
  module Merginator
8
- class Error < StandardError; end
9
-
10
8
  def self.pattern_merge(...)
11
9
  PatternMerge.new(...)
12
10
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/merginator/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'merginator'
7
+ spec.version = Merginator::VERSION
8
+ spec.authors = ['Ryan Verhey']
9
+ spec.email = ['ryan@ryanverhey.com']
10
+
11
+ spec.summary = 'Merging collections based on a pattern.'
12
+ spec.description = 'Merge 2 or more collections based on a repeating pattern.'
13
+ spec.homepage = 'https://github.com/RyanVerhey/merginator'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 2.7.8'
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'https://github.com/RyanVerhey/merginator'
19
+ spec.metadata['changelog_uri'] = 'https://github.com/RyanVerhey/merginator/blob/main/CHANGELOG.md'
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(__dir__) do
24
+ `git ls-files -z`.split("\x0").reject do |f|
25
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
26
+ end
27
+ end
28
+ spec.bindir = 'exe'
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+
32
+ # Uncomment to register a new dependency of your gem
33
+ # spec.add_dependency "example-gem", "~> 1.0"
34
+
35
+ # For more information and examples about making a new gem, check out our
36
+ # guide at: https://bundler.io/guides/creating_gem.html
37
+ spec.metadata['rubygems_mfa_required'] = 'true'
38
+ end
@@ -0,0 +1,18 @@
1
+ ---
2
+ sources:
3
+ - type: git
4
+ name: ruby/gem_rbs_collection
5
+ revision: 87fba082504c606c03edf724cdf2e119bcd46c8c
6
+ remote: https://github.com/ruby/gem_rbs_collection.git
7
+ repo_dir: gems
8
+ path: ".gem_rbs_collection"
9
+ gems:
10
+ - name: minitest
11
+ version: '0'
12
+ source:
13
+ type: stdlib
14
+ - name: mutex_m
15
+ version: '0'
16
+ source:
17
+ type: stdlib
18
+ gemfile_lock_path: Gemfile.lock
@@ -0,0 +1,20 @@
1
+ # Download sources
2
+ sources:
3
+ - type: git
4
+ name: ruby/gem_rbs_collection
5
+ remote: https://github.com/ruby/gem_rbs_collection.git
6
+ revision: main
7
+ repo_dir: gems
8
+
9
+ # You can specify local directories as sources also.
10
+ # - type: local
11
+ # path: path/to/your/local/repository
12
+
13
+ # A directory to install the downloaded RBSs
14
+ path: .gem_rbs_collection
15
+
16
+ gems:
17
+ # Skip loading rbs gem's RBS.
18
+ # It's unnecessary if you don't use rbs as a library.
19
+ - name: rbs
20
+ ignore: true
@@ -1,15 +1,24 @@
1
1
  # See the writing guide of rbs: https://github.com/ruby/rbs#guides
2
+ type wrapper = Array[untyped]
3
+ type collection = Array[untyped]
4
+ type total = Integer?
5
+
2
6
  class Merginator::PatternMerge
3
- @pattern: Array[Integer]
4
- @total: Integer
5
- @counts: Array[Integer]?
7
+ attr_reader pattern: Array[Integer]
8
+ attr_reader total: total
9
+ attr_reader counts: Array[Integer]?
10
+ attr_reader wrapper: wrapper
6
11
 
7
- def merge: (*Enumerable[untyped]) -> Array[untyped]
12
+ def initialize: (*Integer, ?total: total, ?wrapper: wrapper) -> void
13
+ def merge: (*collection, ?wrapper: wrapper, ?ignore_total: bool) -> wrapper
8
14
 
9
15
  private
10
16
 
11
- def generate_pattern_counts: (Integer) -> Array[Integer]
17
+ def generate_pattern_counts: (total) -> Array[Integer]?
18
+ def slice_collections: (Array[collection]) -> Array[Array[untyped]]
19
+ def merge_collections_into_wrapper: (Array[Array[untyped]], wrapper: wrapper, total: Integer) -> wrapper
12
20
  def validate_pattern: () -> void
13
21
  def validate_total: () -> void
14
- def validate_merge_collections: (*Enumerable[untyped]) -> void
22
+ def validate_merge_collections: (Array[collection]) -> void
23
+ def validate_wrapper: (?wrapper) -> void
15
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: merginator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Verhey
@@ -26,9 +26,13 @@ files:
26
26
  - LICENSE.txt
27
27
  - README.md
28
28
  - Rakefile
29
+ - Steepfile
29
30
  - lib/merginator.rb
30
31
  - lib/merginator/pattern_merge.rb
31
32
  - lib/merginator/version.rb
33
+ - merginator.gemspec
34
+ - rbs_collection.lock.yaml
35
+ - rbs_collection.yaml
32
36
  - sig/mergifier/pattern_merge.rbs
33
37
  - sig/merginator.rbs
34
38
  homepage: https://github.com/RyanVerhey/merginator