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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 72934fe1a38a001b59b01610c918b4d1fc721b1bad7c93d88b98e29de27c5afa
4
- data.tar.gz: 58a8843c180c16feb72ffa296063d0f102c91f453334783370fe0c179b8d24fc
3
+ metadata.gz: 14628de7ded50f9ae6e12b409973ec0e72e13edd5ea3178ae5f7298a0d11e17a
4
+ data.tar.gz: 0d97cea942b71db034204bfc07d9bc51d14f3ceb7db2ff57641e06a3ea5d08b4
5
5
  SHA512:
6
- metadata.gz: e63d6154357dc6b659189f5b0af701933e5cffb7f80d18f57d66726d3bd5c939d808f186184cff799c129aaaa014b820af5fa6aecac1da8636b6a7e9b89dea48
7
- data.tar.gz: e13bc6151cc4e6f7a025a36d6ed0c766b075ffd66f4bab4e4adc97f3ae73c352b5c6d7357dd0227dd249f8eb7f61d7dd41dfbf8770b561a517ff3822f26a145f
6
+ metadata.gz: 72ad7f946e863dbae77566f46db776db2db05da357ff268937ede5d044da423e87b6c0b426ee8d88ca742631074eda6797f605f7319ed1c17bb1b655dd47ba3b
7
+ data.tar.gz: 2c60faa04871eeae5c75a88003d16bb0cfa6509251d0b004f51067881bd88e22580a1bf432bf11e8789c68e3585f6d4b0973d0f2eb078a1acadeaa21082046e4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- clausewitz-spelling (0.2.4)
4
+ clausewitz-spelling (0.2.5)
5
5
  colorize
6
6
  damerau-levenshtein
7
7
  ffi-hunspell-wtchappell
@@ -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!(/£\w+/, '')
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 { |word| check_word(word, lc) }.compact
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.to_s.red : "#{@filepath} passed".green
16
- failures = @lang_results.select(&:failed?)
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
@@ -1,5 +1,5 @@
1
1
  module Clausewitz
2
2
  module Spelling
3
- VERSION = "0.2.4"
3
+ VERSION = "0.2.5"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clausewitz-spelling
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Will Chappell