comma_splice 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dd12b113b4440991523636f0cb9e7cf193394704cf12234f640632001bee96fa
4
- data.tar.gz: 9ad043ca537cef2ab6e3ada54e56e07c04e762c58d3ecca314b894222e86ca42
3
+ metadata.gz: 7f6b56980107ae3e81c5d61f6331f4eedcd21d6120f145f6a3b4e18c79a4d63b
4
+ data.tar.gz: cf3bac98bb36e2a94f6d939b54496d803cbc7078ee044b1972f66450b667628e
5
5
  SHA512:
6
- metadata.gz: d1efb0c81ae6927969ac5e142d94553f845a454620774c333b23a97d4afffca93a8929156f8b2216d2360446fcf97f986d09ba4e1a4983b25f59822f07cef406
7
- data.tar.gz: 5cabfeb12c2329e1d8ed3be5c0518435863a0d63dd7c226c11dd3339cca1c38990b0527b20ceb000e1c3ad4cdaed53235041d5741a63ccae56eb393909e5e2ba
6
+ metadata.gz: 17025c468ae170c2e7a3a3b8555072208181e1a020dbd835d8ee4ced13d7dd91c8eca4f99b6c27ce25b279e2f6a2354c0af734c42446a2cf31375d572d8c283d
7
+ data.tar.gz: dd0bf6268d3ee42443a143e6d99df65c56bb65703eddf0e67f10d86651af9c7a56f2ae3199bb31d39a03ae1d7cc673a4de9278abb6922e0fd5ce8dd68e082bf1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ### 0.2.2 (January 27, 2020)
4
+ - [BUGFIX] Fix another scoring issue
5
+
3
6
  ### 0.2.1 (January 26, 2020)
4
7
  - [BUGFIX] Remove debug information from option output
5
8
  - [IMPROVEMENT] Add debug option to display scoring info
data/Gemfile CHANGED
@@ -1,3 +1,4 @@
1
1
  source "https://rubygems.org"
2
2
  # Specify your gem's dependencies in comma_splice.gemspec
3
+ gem 'simplecov', require: false, group: :test
3
4
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- comma_splice (0.2.1)
4
+ comma_splice (0.2.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -14,8 +14,10 @@ GEM
14
14
  byebug (11.0.1)
15
15
  concurrent-ruby (1.1.5)
16
16
  diff-lcs (1.3)
17
+ docile (1.3.2)
17
18
  i18n (1.6.0)
18
19
  concurrent-ruby (~> 1.0)
20
+ json (2.3.0)
19
21
  minitest (5.11.3)
20
22
  rake (10.5.0)
21
23
  rspec (3.8.0)
@@ -31,6 +33,11 @@ GEM
31
33
  diff-lcs (>= 1.2.0, < 2.0)
32
34
  rspec-support (~> 3.8.0)
33
35
  rspec-support (3.8.2)
36
+ simplecov (0.17.1)
37
+ docile (~> 1.1)
38
+ json (>= 1.8, < 3)
39
+ simplecov-html (~> 0.10.0)
40
+ simplecov-html (0.10.2)
34
41
  thor (0.20.3)
35
42
  thread_safe (0.3.6)
36
43
  tzinfo (1.2.5)
@@ -46,6 +53,7 @@ DEPENDENCIES
46
53
  comma_splice!
47
54
  rake (~> 10.0)
48
55
  rspec
56
+ simplecov
49
57
  thor
50
58
 
51
59
  BUNDLED WITH
@@ -8,8 +8,9 @@ module CommaSplice
8
8
  def initialize(headers, values)
9
9
  raise StandardError, "Determining all the possibilities to fit #{values.size} values into the #{headers.size} headers #{headers.inspect} is computationally expensive. Please specify the columns where commas might be." if headers.size > 10 && values.size > 10
10
10
 
11
- @headers = headers
12
- @values = values
11
+ @headers = headers
12
+ @values = values
13
+ @longest_header = @headers.max_by(&:length)
13
14
  end
14
15
 
15
16
  def correction
@@ -20,11 +21,11 @@ module CommaSplice
20
21
  elsif best_options.size > 1
21
22
  prompt_for_options(best_options)
22
23
  else
23
- prompt_for_options(all_options)
24
+ prompt_for_options(ranked_options)
24
25
  end
25
26
  end
26
27
 
27
- def all_options
28
+ def ranked_options
28
29
  @all_options ||= join_possibilities.collect do |joins|
29
30
  values = @values.dup
30
31
  joins.collect do |join_num|
@@ -38,10 +39,8 @@ module CommaSplice
38
39
  end
39
40
  end
40
41
  end
41
- end
42
42
 
43
- def ranked_options
44
- @ranked_options ||= all_options.collect do |option|
43
+ @ranked_options ||= @all_options.collect do |option|
45
44
  OptionScorer.new(option)
46
45
  end
47
46
  end
@@ -70,32 +69,11 @@ module CommaSplice
70
69
  end
71
70
 
72
71
  def prompt_for_options(options)
73
- longest_header = @headers.max_by(&:length)
74
-
75
72
  options.each_with_index do |option, index|
76
- score_breakdown = option.breakdown
77
-
78
- @headers.each_with_index do |header, i|
79
- marker = if i.zero?
80
- "(#{index + 1})"
81
- else
82
- ''
83
- end
84
-
85
- line = marker.ljust(7) +
86
- header.ljust(longest_header.size) + ': ' +
87
- option.option[i].to_s.ljust(75)
88
-
89
- if CommaSplice.debug
90
- line = line + "| " + (score_breakdown.shift || "")
91
- end
92
- puts line
93
- end
94
-
95
- puts "\n"
73
+ print_option(option, index)
96
74
  end
97
75
 
98
- puts "press 0 to see all options" if all_options.size != options.size
76
+ puts "press 0 to see all options" if ranked_options.size != options.size
99
77
 
100
78
  selected_option = nil
101
79
  until selected_option && selected_option.to_i > -1
@@ -109,5 +87,30 @@ module CommaSplice
109
87
  options[selected_option.to_i - 1].option
110
88
  end
111
89
  end
90
+
91
+ def print_option(option, index = nil)
92
+ score_breakdown = option.breakdown
93
+
94
+ lines = []
95
+ @headers.each_with_index do |header, i|
96
+ marker = if i.zero? && index
97
+ "(#{index + 1})"
98
+ else
99
+ ''
100
+ end
101
+
102
+ line = marker.ljust(7) +
103
+ header.ljust(@longest_header.size) + ': ' +
104
+ option.option[i].to_s.ljust(75)
105
+
106
+ if CommaSplice.debug
107
+ line = line + "| " + (score_breakdown.shift || "")
108
+ end
109
+
110
+ lines << line
111
+ end
112
+ lines << "\n"
113
+ puts lines.join("\n")
114
+ end
112
115
  end
113
116
  end
@@ -1,6 +1,5 @@
1
1
  module CommaSplice
2
2
  # scores options based on how likely they are to be correct
3
-
4
3
  class OptionScorer
5
4
  attr_reader :option
6
5
 
@@ -58,7 +57,7 @@ module CommaSplice
58
57
 
59
58
  def options_that_have_words_joined_by_commas
60
59
  option.select do |o|
61
- o.to_s.match(/[A-Za-z],[A-Za-z]/)
60
+ o.to_s.match(/[^0-9],[\w]/) || o.to_s.match(/[^\w],[0-9]/)
62
61
  end.compact.size * -5
63
62
  end
64
63
 
@@ -109,6 +108,5 @@ module CommaSplice
109
108
  def rules
110
109
  methods.grep(/options_that/)
111
110
  end
112
-
113
111
  end
114
112
  end
@@ -18,13 +18,17 @@ module CommaSplice
18
18
  end
19
19
 
20
20
  def needs_correcting?
21
- @values && @values.size > 0 && @headers.size != @values.size
21
+ @values && @values.size.positive? && @headers.size != @values.size
22
22
  end
23
23
 
24
24
  def needs_manual_input?
25
25
  corrector.needs_manual_input?
26
26
  end
27
27
 
28
+ def option_count
29
+ corrector.best_options.size
30
+ end
31
+
28
32
  def original
29
33
  generate_csv_line(@values)
30
34
  end
@@ -1,3 +1,3 @@
1
1
  module CommaSplice
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comma_splice
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Keen