merginator 0.1.1 → 0.2.2

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: cec09691fc1e5abd0eb16409a89002e835b565c1f030235d58e01143a090419a
4
+ data.tar.gz: 84dc992b1e3567c82ef5d53d280d8708105a81186d71b4adc592d1284d75fec4
5
5
  SHA512:
6
- metadata.gz: 91709f61f93ae9b2296a935d06fdf69d6f8c8722ee91546d87329faa20a95e56be5b3d8fe4d62c6fcf8f7d55df41dfc5740d743a04097332d71cae1779f3e3f8
7
- data.tar.gz: 04004fb039e34a98ee2803f7d33da2d3654d280929299fd2121c11455992441183da5c6f55be3e8e51d5a9494e35158313ff9c57ed1a3231ef3af3b5971632c6
6
+ metadata.gz: 4238899209c3d5fbf18a3f4d72ff0167ac0d4218f338f9ae09ef78cc798e9798456729d41ebcadd3fa01df75b0758fcf5096af3e3b4ba3eb1db024f2a0b06eb0
7
+ data.tar.gz: e1b1b285d7dee050ab08a2100794f82a0a993ac40f26dc12af30c98f04ab5cd2c1d4e1e6edf56ff595844490d44fda3d648edb7db2bab19dad761247729086b6
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,16 @@
1
+ ## [0.2.2] - 2023-06-30
2
+
3
+ - Updating ignore total behavior to actually ignore total when validating
4
+
5
+ ## [0.2.1] - 2023-06-27
6
+
7
+ - Configuration change version bump
8
+
9
+ ## [0.2.0] - 2023-06-27
10
+
11
+ - Updating configuration
12
+ - Improving functionality based on usage
13
+
1
14
  ## [0.1.1] - 2023-06-26
2
15
 
3
16
  - 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.2)
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,33 @@ 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)
25
- validate_merge_collections(collections)
27
+ def merge(*collections, wrapper: @wrapper, ignore_total: false)
28
+ validate_merge_collections(collections, ignore_total: ignore_total)
29
+ validate_wrapper wrapper
26
30
 
27
- total = @total || collections.sum(&:size)
31
+ total_to_use = total_to_use(collections, ignore_total: ignore_total)
28
32
 
29
- slices_for_collections = collections.map.with_index do |collection, index|
30
- collection.each_slice(@pattern[index]).to_a
31
- end
33
+ slices_for_collections = slice_collections(collections)
34
+ merge_collections_into_wrapper(slices_for_collections, wrapper: wrapper, total: total_to_use)
32
35
 
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)
36
+ wrapper
37
37
  end
38
38
 
39
39
  private
@@ -44,6 +44,8 @@ module Merginator
44
44
  # Merginator::Mergifier::PatternMerge.new(4, 2, 1, total: 25)
45
45
  # => [16, 6, 3]
46
46
  def generate_pattern_counts(total)
47
+ return unless total
48
+
47
49
  full_repetitions = total / @pattern.sum
48
50
  counts = @pattern.map { |num| num * full_repetitions }
49
51
 
@@ -57,27 +59,55 @@ module Merginator
57
59
  counts
58
60
  end
59
61
 
62
+ def slice_collections(collections)
63
+ collections.map.with_index do |collection, index|
64
+ collection.each_slice(@pattern[index]).to_a
65
+ end
66
+ end
67
+
68
+ def merge_collections_into_wrapper(slices_for_collections, wrapper:, total:)
69
+ slices_for_collections.map(&:size).max.to_i.times.each_with_object(wrapper) do |index, wrapper_obj|
70
+ wrapper_obj.concat slices_for_collections.map { |slices| slices[index] || [] }.flatten
71
+ break(wrapper_obj) if wrapper_obj.size >= total
72
+ end
73
+
74
+ wrapper.replace wrapper.take(total)
75
+ end
76
+
77
+ def total_to_use(collections, ignore_total: false)
78
+ !@total || ignore_total ? collections.sum(&:size) : @total.to_i
79
+ end
80
+
60
81
  def validate_pattern
61
82
  raise ArgumentError, 'there must be more than one collection in the pattern' if @pattern.count <= 1
62
83
  raise ArgumentError, 'pattern must be all integers' unless @pattern.all? { |n| n.is_a? Integer }
63
84
  end
64
85
 
65
86
  def validate_total
66
- raise ArgumentError, 'total must be at least 1' if @total && @total < 1
87
+ return if (@total || 1).positive?
88
+
89
+ raise ArgumentError, 'total must be at least 1'
67
90
  end
68
91
 
69
- def validate_merge_collections(collections)
92
+ def validate_merge_collections(collections, ignore_total: false)
70
93
  unless @pattern.count == collections.count
71
94
  message = 'number of collections must match pattern; '
72
95
  message += "expected #{@pattern.count} collections, actual: #{collections.count}"
73
96
  raise ArgumentError, message
74
97
  end
75
98
 
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
99
+ total_to_use = total_to_use(collections, ignore_total: ignore_total)
100
+ return if collections.sum(&:size) >= total_to_use
101
+
102
+ message = 'total number of elements in collections must be >= provided total; '
103
+ message += "expected #{@total} elements, actual: #{collections.flatten.count}"
104
+ raise ArgumentError, message
105
+ end
106
+
107
+ def validate_wrapper(wrapper = @wrapper)
108
+ return if wrapper.is_a?(Array)
109
+
110
+ raise ArgumentError, 'wrapper must be like an array'
81
111
  end
82
112
  end
83
113
  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.2'
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
@@ -0,0 +1,25 @@
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
+
6
+ class Merginator::PatternMerge
7
+ attr_reader pattern: Array[Integer]
8
+ attr_reader total: total
9
+ attr_reader counts: Array[Integer]?
10
+ attr_reader wrapper: wrapper
11
+
12
+ def initialize: (*Integer, ?total: total, ?wrapper: wrapper) -> void
13
+ def merge: (*collection, ?wrapper: wrapper, ?ignore_total: bool) -> wrapper
14
+
15
+ private
16
+
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
20
+ def total_to_use: (Array[collection], ?ignore_total: bool) -> Integer
21
+ def validate_pattern: () -> void
22
+ def validate_total: () -> void
23
+ def validate_merge_collections: (Array[collection], ?ignore_total: bool) -> void
24
+ def validate_wrapper: (?wrapper) -> void
25
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
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.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Verhey
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-27 00:00:00.000000000 Z
11
+ date: 2023-06-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Merge 2 or more collections based on a repeating pattern.
14
14
  email:
@@ -26,11 +26,15 @@ 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
32
- - sig/mergifier/pattern_merge.rbs
33
+ - merginator.gemspec
34
+ - rbs_collection.lock.yaml
35
+ - rbs_collection.yaml
33
36
  - sig/merginator.rbs
37
+ - sig/pattern_merge.rbs
34
38
  homepage: https://github.com/RyanVerhey/merginator
35
39
  licenses:
36
40
  - MIT
@@ -1,15 +0,0 @@
1
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
2
- class Merginator::PatternMerge
3
- @pattern: Array[Integer]
4
- @total: Integer
5
- @counts: Array[Integer]?
6
-
7
- def merge: (*Enumerable[untyped]) -> Array[untyped]
8
-
9
- private
10
-
11
- def generate_pattern_counts: (Integer) -> Array[Integer]
12
- def validate_pattern: () -> void
13
- def validate_total: () -> void
14
- def validate_merge_collections: (*Enumerable[untyped]) -> void
15
- end