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 +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +9 -1
- data/lib/comma_splice/helpers/comma_calculator.rb +33 -30
- data/lib/comma_splice/helpers/option_scorer.rb +1 -3
- data/lib/comma_splice/line_corrector.rb +5 -1
- data/lib/comma_splice/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f6b56980107ae3e81c5d61f6331f4eedcd21d6120f145f6a3b4e18c79a4d63b
|
4
|
+
data.tar.gz: cf3bac98bb36e2a94f6d939b54496d803cbc7078ee044b1972f66450b667628e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17025c468ae170c2e7a3a3b8555072208181e1a020dbd835d8ee4ced13d7dd91c8eca4f99b6c27ce25b279e2f6a2354c0af734c42446a2cf31375d572d8c283d
|
7
|
+
data.tar.gz: dd0bf6268d3ee42443a143e6d99df65c56bb65703eddf0e67f10d86651af9c7a56f2ae3199bb31d39a03ae1d7cc673a4de9278abb6922e0fd5ce8dd68e082bf1
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
comma_splice (0.2.
|
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
|
12
|
-
@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(
|
24
|
+
prompt_for_options(ranked_options)
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
27
|
-
def
|
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
|
-
|
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
|
-
|
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
|
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(/[
|
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
|
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
|
data/lib/comma_splice/version.rb
CHANGED