group_by_match_type 0.1.0 → 0.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: 5202086856b91a26669f161ea8edc6982fd6dd8fc6e62e375e4bd334727de16c
4
- data.tar.gz: 4b3c5911103ed26e80ffb6ddff7bc77dd3c9b83d7ba19ab0a787c652def1f407
3
+ metadata.gz: 1e02ae439383bee301cbfe85d02b557dc55883b5259bd11b701030f2d5b7a36d
4
+ data.tar.gz: b2cc916743083fb97352d194fe64713c4738bf4603be7f4ca5ff2ef786998ce0
5
5
  SHA512:
6
- metadata.gz: f5167852ae2269c04129ad5a859af81a2e2addaf90db7db1ca72cbf417df91dac9327f263de05e9a8151e9be8dbd587551693b69875558caf8dec4cdb16ffa30
7
- data.tar.gz: 27809eb8566ecc18b886fa35fa300725323db17bb51bda0153c72c99df36ba4acb675a644213a1f756421d95da98700774d67f2855501b1ecf173a00871b1fa5
6
+ metadata.gz: 59ab1c266cffceb1598be59aed1dcdc532a27a252f544d80028791947fb4f94ca24cd0c77b1b56b582ebe62b014205736f7f6afd169974d1cbb11ae066747da5
7
+ data.tar.gz: 5a8676a87c866a8c740e71253833024f3d048306601385e48f982e7a193fdb1ff0542d2377695dbd0f9afd49c25c225f5250d6cc715ba56db8221c450ee88dac
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'group_by_match_type'
4
5
  require 'group_by_match_type/cli'
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'optparse'
2
4
  require_relative 'matcher'
3
5
 
4
6
  module GroupByMatchType
5
7
  class CLI
6
- VALID_TYPES = %w[same_email same_phone same_email_or_phone]
8
+ VALID_TYPES = %w[same_email same_phone same_email_or_phone].freeze
7
9
 
8
10
  def self.start(args)
9
11
  if args.empty? || args.include?('-h') || args.include?('--help')
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'csv'
2
4
  require_relative 'union_find'
3
5
 
@@ -28,11 +30,11 @@ module GroupByMatchType
28
30
  # Determine output file path
29
31
  output_file ||= @input_file.sub(/\.csv$/, '_grouped.csv')
30
32
  CSV.open(output_file, 'w') do |csv|
31
- csv << rows.headers + ['group_id']
33
+ csv << ['group_id'] + rows.headers
32
34
  rows.each_with_index do |row, index|
33
35
  root = @union_find.find(index.to_s)
34
36
  group_id = group_id_map[root]
35
- csv << row.fields + [group_id]
37
+ csv << [group_id] + row.fields
36
38
  end
37
39
  end
38
40
 
@@ -1,26 +1,29 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GroupByMatchType
2
4
  class UnionFind
3
5
  def initialize
4
6
  @parent = {}
5
7
  end
6
8
 
7
- def find(x)
8
- @parent[x] = find(@parent[x]) if @parent[x] && @parent[x] != x
9
- @parent[x] ||= x
9
+ def find(item)
10
+ @parent[item] = find(@parent[item]) if @parent[item] && @parent[item] != item
11
+ @parent[item] ||= item
10
12
  end
11
13
 
12
- def union(x, y)
13
- root_x = find(x)
14
- root_y = find(y)
15
- @parent[root_x] = root_y unless root_x == root_y
14
+ def union(source_item, target_item)
15
+ source_root = find(source_item)
16
+ target_root = find(target_item)
17
+ @parent[source_root] = target_root unless source_root == target_root
16
18
  end
17
19
 
18
20
  def find_or_create(items)
19
21
  return nil if items.empty?
22
+
20
23
  items.map!(&:to_s)
21
24
  roots = items.map { |item| find(item) }
22
25
  main_root = roots.first
23
- roots[1..].each { |r| union(main_root, r) }
26
+ roots[1..].each { |root| union(main_root, root) }
24
27
  main_root
25
28
  end
26
29
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GroupByMatchType
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: group_by_match_type
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Boltz