cr.rb 4.1.1 → 4.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/cr +5 -2
  3. data/lib/cr/version.rb +1 -1
  4. data/lib/cr.rb +22 -11
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 900040b08ba030c166a96a350fe5c0764d3ed527319240cd5c09a83af03a3890
4
- data.tar.gz: f0b2f1bc7abaf49c649107ab45a436c9ba7ce63af9665fa23b02064fbbef60ae
3
+ metadata.gz: 572931031815b1f284c44e722df17147b330a853439f79f0953946bfb42bb69d
4
+ data.tar.gz: 653b3090e8f85a8b962d3d62d0a3a5e362e65c4abb5db506b7b2d2091ff343ab
5
5
  SHA512:
6
- metadata.gz: 5f4b18c9828c07b1da421501d6c9bf898c475ae6784d8d7864ded3295df51ea43c1ac0f3e0178a6cede1ea224d62bb5f3f1d634dc13960b512e9f7fd00898aa2
7
- data.tar.gz: 5bec78a9df8f94ae2a1f72d27da6ea755cf315258f8247c84029ece1802bfdb47e056bb6b07956ae666dc1506dfeaa5090610c1b68dba9d7af9d149ee771c46d
6
+ metadata.gz: f105ec4f493687a15e205b8ded554172a47369c5ed61a4dd0139ca335005cb73d56284c8bd881acb6f50b62fe89ae9a996a9dacecfaf0a1d0bffa53d107036bd
7
+ data.tar.gz: db01b4bdcc86d62017d043db81c561e1f5e14b56931aeaacf820b31c7f9ee8d524912dd0bdb78ef0ea011f4eb8697e8e6cd090a15e8b7888e14798a6ae060128
data/bin/cr CHANGED
@@ -3,7 +3,7 @@
3
3
  # File : cr.rb
4
4
  # Authors : ccmywish <ccmywish@qq.com>
5
5
  # Created on : <2021-07-08>
6
- # Last modified : <2023-02-12>
6
+ # Last modified : <2023-02-13>
7
7
  #
8
8
  # cr:
9
9
  #
@@ -518,7 +518,10 @@ A info looks like this
518
518
 
519
519
  # Try to match every word in all dicts
520
520
  Dir.children(library).each do |dict|
521
- sheets = Dir.children(File.join(library, dict)).select do
521
+
522
+ path = File.join(library, dict)
523
+ next if File.file? path
524
+ sheets = Dir.children(path).select do
522
525
  _1.end_with?('.toml')
523
526
  end
524
527
 
data/lib/cr/version.rb CHANGED
@@ -11,6 +11,6 @@
11
11
 
12
12
  module CrypticResolver
13
13
 
14
- GEM_VERSION = "4.1.1"
14
+ GEM_VERSION = "4.1.3"
15
15
 
16
16
  end
data/lib/cr.rb CHANGED
@@ -153,8 +153,10 @@ class CrypticResolver::Resolver
153
153
  abort "cr: Cancel add default dicts"
154
154
  end
155
155
 
156
- puts "cr: Add done" ; word_count
157
- puts ; puts "#{$DefaultLibWordCount} words added"
156
+ puts "cr: Add done" ;
157
+ @counter.count_def_lib(display: false)
158
+ puts ; puts "#{@counter.word_count_of_def_lib} words added"
159
+ @counter.reset!
158
160
 
159
161
  # Really added
160
162
  return true
@@ -184,13 +186,15 @@ class CrypticResolver::Resolver::Counter
184
186
  @resolver = resolver
185
187
  end
186
188
 
187
-
189
+ # a.toml
190
+ # b.toml
191
+ # ...
188
192
  def count_dict_words(library, dict)
189
193
  dict_dir = library + "/#{dict}"
190
194
  wc = 0
191
195
  Dir.children(dict_dir).each do |entry|
192
- next if File.file? entry
193
196
  next unless entry.end_with?('.toml')
197
+ next if File.directory? dict_dir + "/#{entry}"
194
198
  sheet_content = @resolver.load_sheet(library, dict, entry.delete_suffix('.toml'))
195
199
  count = sheet_content.keys.count
196
200
 
@@ -202,12 +206,13 @@ class CrypticResolver::Resolver::Counter
202
206
 
203
207
  # Count default library
204
208
  def count_def_lib(display: )
205
- default_lib = Dir.children(CrypticResolver::Resolver::DEFAULT_LIB_PATH)
209
+ path = CrypticResolver::Resolver::DEFAULT_LIB_PATH
210
+ default_lib = Dir.children path
206
211
  unless default_lib.empty?
207
212
  puts bold(green("Default library: ")) if display
208
213
  default_lib.each do |s|
209
- next if File.file? s
210
- wc = count_dict_words(CrypticResolver::Resolver::DEFAULT_LIB_PATH,s)
214
+ next if File.file? path + "/#{s}"
215
+ wc = count_dict_words(path,s)
211
216
  @word_count_of_def_lib += wc
212
217
  # With color, ljust not works, so we disable color
213
218
  puts("#{wc.to_s.rjust(5)} #{s}") if display
@@ -220,12 +225,11 @@ class CrypticResolver::Resolver::Counter
220
225
  # Count extra library
221
226
  def count_extra_lib(display: )
222
227
  if path = @resolver.extra_lib_path
223
- extra_lib = Dir.children(path)
228
+ extra_lib = Dir.children path
224
229
  unless extra_lib.empty?
225
- wc = 0
226
- puts(bold(green("\nExtra library:"))) if display
230
+ puts bold(green("\nExtra library:")) if display
227
231
  extra_lib.each do |s|
228
- next if File.file? s
232
+ next if File.file? path + "/#{s}"
229
233
  wc = count_dict_words(path,s)
230
234
  @word_count_of_extra_lib += wc
231
235
  puts("#{wc.to_s.rjust(5)} #{s}") if display
@@ -249,4 +253,11 @@ class CrypticResolver::Resolver::Counter
249
253
  end
250
254
  end
251
255
 
256
+
257
+ def reset!
258
+ @word_count_of_two_libs = 0
259
+ @word_count_of_def_lib = 0
260
+ @word_count_of_extra_lib = 0
261
+ end
262
+
252
263
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cr.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.1
4
+ version: 4.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aoran Zeng