clausewitz-spelling 0.2.4 → 0.2.5
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/clausewitz/spelling/checker.rb +13 -3
- data/lib/clausewitz/spelling/results.rb +45 -4
- data/lib/clausewitz/spelling/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: 14628de7ded50f9ae6e12b409973ec0e72e13edd5ea3178ae5f7298a0d11e17a
|
4
|
+
data.tar.gz: 0d97cea942b71db034204bfc07d9bc51d14f3ceb7db2ff57641e06a3ea5d08b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72ad7f946e863dbae77566f46db776db2db05da357ff268937ede5d044da423e87b6c0b426ee8d88ca742631074eda6797f605f7319ed1c17bb1b655dd47ba3b
|
7
|
+
data.tar.gz: 2c60faa04871eeae5c75a88003d16bb0cfa6509251d0b004f51067881bd88e22580a1bf432bf11e8789c68e3585f6d4b0973d0f2eb078a1acadeaa21082046e4
|
data/Gemfile.lock
CHANGED
@@ -21,6 +21,8 @@ module Clausewitz; module Spelling
|
|
21
21
|
@suggestion_count = opts[:suggestion_count] || DEFAULT_SUGGESTION_COUNT
|
22
22
|
@verbose = opts[:verbose]
|
23
23
|
|
24
|
+
@check_cache = {}
|
25
|
+
|
24
26
|
load_dictionaries!
|
25
27
|
end
|
26
28
|
|
@@ -48,7 +50,7 @@ module Clausewitz; module Spelling
|
|
48
50
|
end
|
49
51
|
|
50
52
|
def check_file(filepath)
|
51
|
-
puts "Checking file '#{filepath}'..." if @verbose
|
53
|
+
$stderr.puts "Checking file '#{filepath}'..." if @verbose
|
52
54
|
results = []
|
53
55
|
begin
|
54
56
|
filepath = Pathname.new(filepath)
|
@@ -104,7 +106,7 @@ module Clausewitz; module Spelling
|
|
104
106
|
|
105
107
|
# Remove other localisation bits we don't care about.
|
106
108
|
entry.gsub!(/§(%|\*|=|\d|W|G|R|B|Y|b|M|g|T|l|H|\+|-|!)/, '')
|
107
|
-
entry.gsub!(
|
109
|
+
entry.gsub!(/(£|\$)\w+(\|.+\$)?/, '')
|
108
110
|
|
109
111
|
## We should also remove punctuation that is never part of words, like
|
110
112
|
## exclamation points, commas, semi-colons, and question marks.
|
@@ -148,11 +150,19 @@ module Clausewitz; module Spelling
|
|
148
150
|
end
|
149
151
|
end
|
150
152
|
|
151
|
-
checks = words.map
|
153
|
+
checks = words.map do |word|
|
154
|
+
check = check_word(word, lc)
|
155
|
+
unless @check_cache.key?([[word, lc]])
|
156
|
+
@check_cache[[word, lc]] = check
|
157
|
+
end
|
158
|
+
check
|
159
|
+
end.compact
|
152
160
|
EntryResults.new(key, checks)
|
153
161
|
end
|
154
162
|
|
155
163
|
def check_word(word, lc)
|
164
|
+
return @check_cache[[word, lc]] if @check_cache.key?([word, lc])
|
165
|
+
|
156
166
|
return if is_number?(word)
|
157
167
|
return if is_plural_number?(word)
|
158
168
|
return if is_ordinal?(word)
|
@@ -7,13 +7,30 @@ module Clausewitz; module Spelling
|
|
7
7
|
@lang_results = lang_results
|
8
8
|
end
|
9
9
|
|
10
|
+
def ignored?
|
11
|
+
@lang_results.all?(&:ignored?)
|
12
|
+
end
|
13
|
+
|
10
14
|
def failed?
|
11
15
|
@lang_results.any?(&:failed?)
|
12
16
|
end
|
13
17
|
|
18
|
+
def failures
|
19
|
+
@lang_results.select(&:failed?)
|
20
|
+
end
|
21
|
+
|
22
|
+
def failure_total
|
23
|
+
failures.reduce(0) { |memo, obj| memo += obj.failures.size }
|
24
|
+
end
|
25
|
+
|
26
|
+
def size
|
27
|
+
@lang_results.reduce(0) { |memo, obj| memo += obj.size }
|
28
|
+
end
|
29
|
+
|
14
30
|
def to_s
|
15
|
-
outfile = failed? ? @filepath.
|
16
|
-
|
31
|
+
outfile = failed? ? "#{@filepath} has #{failure_total} errors (#{size} total keys checked)".red : "#{@filepath} passed (#{size} total keys checked)".green
|
32
|
+
outfile = ignored? ? "#{@filepath} ignored".yellow : outfile
|
33
|
+
interesting = @lang_results.select { |l| l.failed? || l.ignored? }
|
17
34
|
"#{outfile}\n" + failures.map { |l| " #{l}" }.join("\n")
|
18
35
|
end
|
19
36
|
end
|
@@ -24,10 +41,22 @@ module Clausewitz; module Spelling
|
|
24
41
|
@entry_results = entry_results
|
25
42
|
end
|
26
43
|
|
44
|
+
def ignored?
|
45
|
+
false
|
46
|
+
end
|
47
|
+
|
27
48
|
def failed?
|
28
49
|
@entry_results.any?(&:failed?)
|
29
50
|
end
|
30
51
|
|
52
|
+
def failures
|
53
|
+
@entry_results.select(&:failed?)
|
54
|
+
end
|
55
|
+
|
56
|
+
def size
|
57
|
+
@entry_results.size
|
58
|
+
end
|
59
|
+
|
31
60
|
def to_s
|
32
61
|
to_str
|
33
62
|
end
|
@@ -38,7 +67,7 @@ module Clausewitz; module Spelling
|
|
38
67
|
failures = @entry_results.select(&:failed?)
|
39
68
|
outlines = failures.map { |e| "#{spacer}#{e.to_str(indent + 2)}" }
|
40
69
|
outlines = outlines.join("\n")
|
41
|
-
outlang = failed? ? @lang.red : @lang.green
|
70
|
+
outlang = failed? ? "#{@lang} has #{failures.size} keys with errors".red : "#{@lang} passed (#{size} keys checked)".green
|
42
71
|
out = "#{firstspacer}#{outlang}\n#{outlines}"
|
43
72
|
end
|
44
73
|
end
|
@@ -48,10 +77,22 @@ module Clausewitz; module Spelling
|
|
48
77
|
@lang = lang
|
49
78
|
end
|
50
79
|
|
80
|
+
def ignored?
|
81
|
+
true
|
82
|
+
end
|
83
|
+
|
51
84
|
def failed?
|
52
85
|
false
|
53
86
|
end
|
54
87
|
|
88
|
+
def failures
|
89
|
+
[]
|
90
|
+
end
|
91
|
+
|
92
|
+
def size
|
93
|
+
0
|
94
|
+
end
|
95
|
+
|
55
96
|
def to_s
|
56
97
|
to_str
|
57
98
|
end
|
@@ -199,7 +240,7 @@ module Clausewitz; module Spelling
|
|
199
240
|
secondspacer = ' ' * (indent + 2)
|
200
241
|
"#{spacer}#{@filepath} could not be parsed\n".red +
|
201
242
|
"#{secondspacer}#{@error.message}\n".red +
|
202
|
-
"Make sure every entry has exactly two spaces in front of it.".red
|
243
|
+
"#{secondspacer}Make sure every entry has exactly two spaces in front of it.".red
|
203
244
|
end
|
204
245
|
end
|
205
246
|
end; end # Clausewitz::Spelling
|