cr.rb 4.1.2 → 4.1.4

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 +21 -11
  3. data/lib/cr/version.rb +2 -2
  4. data/lib/cr.rb +15 -14
  5. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4956248002fc5393f2a85f894239434599f1c10535f90f8f7f80c5996a7b395
4
- data.tar.gz: 4000408dedca70e9234130de2fbf66df60e6973c895f806667e6401e458b5090
3
+ metadata.gz: 624c2bec73d0e1c7af063aec76ce582a38a2b73c56d8680a3d67a8f293b8695b
4
+ data.tar.gz: 49b1c1aa5c178087d94e70d3110c7a7e3b479478723be80c5ff67467c05d1634
5
5
  SHA512:
6
- metadata.gz: 425899ebb33d5fc54080dc4c50583e678442d8f6110f1dfbe1134e96ea5d1d9c2c34665575b0145ec374fdd71d88f8646817be930f44ece8437d9967b2de92c2
7
- data.tar.gz: 84f8c04209eec1c16183eabb511b9a9fd686008e0aaa1cc8525238f61f50195a0b8623010dd7a6fbfab9f7eea0391d06c73fcd123ac77e8fa77a729c4f3cbe41
6
+ metadata.gz: 83b2810d78b2081006474f50df69ab8765327c8c9715d491204548ac4bd5f0c17edb30c5b551a9d30c0d825d93b8d709258a13dc359aa3fce9c9e9c0379893dd
7
+ data.tar.gz: 98c6ac9a3eb0273097d24144013477c7d11cc20ed3818ac79c1779e72b0aad932573b0e39bda08ac1c8c14588ab6929dc2bad6e920e7e287df6e0454b15db9be
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-03-22>
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
 
@@ -553,24 +556,31 @@ A info looks like this
553
556
  # 2. List Extra library's dicts
554
557
  # 3. List official dicts
555
558
  def list_dicts
556
- Dir.chdir DEFAULT_LIB_PATH do
557
- puts blue("=> Default library: #{DEFAULT_LIB_PATH}")
558
- Dir.children(DEFAULT_LIB_PATH).each_with_index do |dict,i|
559
- puts "#{blue(i+1)}. #{bold(green(dict))}"
559
+
560
+ def _do_the_same_thing
561
+ count = 0
562
+ Dir.children(".").each do |dict|
563
+ next if File.file? dict
564
+ count += 1
565
+ prefix = (count.to_s + '.').ljust 4
566
+ puts " #{prefix}#{dict}"
560
567
  end
561
568
  end
562
569
 
570
+ Dir.chdir DEFAULT_LIB_PATH do
571
+ puts bold(green("Default library: #{DEFAULT_LIB_PATH}"))
572
+ _do_the_same_thing
573
+ end
574
+
563
575
  if @extra_lib_path
564
576
  puts
565
577
  Dir.chdir @extra_lib_path do
566
- puts blue("=> Extra library: #{@extra_lib_path}")
567
- Dir.children(@extra_lib_path).each_with_index do |dict,i|
568
- puts "#{blue(i+1)}. #{bold(green(dict))}"
569
- end
578
+ puts bold(green("Extra library: #{@extra_lib_path}"))
579
+ _do_the_same_thing
570
580
  end
571
581
  end
572
582
 
573
- puts ; puts blue("=> Official dicts: (Add it by 'cr -a xxx')")
583
+ puts ; puts bold(green("Official dictionaries: (Add it by 'cr -a xxx')"))
574
584
  puts RECOMMENDED_DICTS
575
585
  end
576
586
 
data/lib/cr/version.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # File : version.rb
3
3
  # Authors : ccmywish <ccmywish@qq.com>
4
4
  # Created on : <2023-02-12>
5
- # Last modified : <2023-02-13>
5
+ # Last modified : <2023-03-22>
6
6
  #
7
7
  # version:
8
8
  #
@@ -11,6 +11,6 @@
11
11
 
12
12
  module CrypticResolver
13
13
 
14
- GEM_VERSION = "4.1.2"
14
+ GEM_VERSION = "4.1.4"
15
15
 
16
16
  end
data/lib/cr.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # File : cr.rb
3
3
  # Authors : ccmywish <ccmywish@qq.com>
4
4
  # Created on : <2022-04-15>
5
- # Last modified : <2023-02-13>
5
+ # Last modified : <2023-03-22>
6
6
  #
7
7
  # cr:
8
8
  #
@@ -55,15 +55,14 @@ class CrypticResolver::Resolver
55
55
  linux technology
56
56
 
57
57
  #{yellow("Field:")}
58
- electronics economy medicine
59
- mechanical science math
58
+ economy medicine electronics
59
+ science math
60
60
 
61
61
  #{yellow("Specific:")}
62
- dos x86 signal
62
+ x86 signal
63
63
 
64
64
  #{yellow("Feature:")}
65
65
  ccmywish/CRuby-Source-Code-Dictionary
66
- ccmywish/mruby-Source-Code-Dictionary
67
66
 
68
67
  EOF
69
68
 
@@ -186,13 +185,15 @@ class CrypticResolver::Resolver::Counter
186
185
  @resolver = resolver
187
186
  end
188
187
 
189
-
188
+ # a.toml
189
+ # b.toml
190
+ # ...
190
191
  def count_dict_words(library, dict)
191
192
  dict_dir = library + "/#{dict}"
192
193
  wc = 0
193
194
  Dir.children(dict_dir).each do |entry|
194
- next if File.file? entry
195
195
  next unless entry.end_with?('.toml')
196
+ next if File.directory? dict_dir + "/#{entry}"
196
197
  sheet_content = @resolver.load_sheet(library, dict, entry.delete_suffix('.toml'))
197
198
  count = sheet_content.keys.count
198
199
 
@@ -204,12 +205,13 @@ class CrypticResolver::Resolver::Counter
204
205
 
205
206
  # Count default library
206
207
  def count_def_lib(display: )
207
- default_lib = Dir.children(CrypticResolver::Resolver::DEFAULT_LIB_PATH)
208
+ path = CrypticResolver::Resolver::DEFAULT_LIB_PATH
209
+ default_lib = Dir.children path
208
210
  unless default_lib.empty?
209
211
  puts bold(green("Default library: ")) if display
210
212
  default_lib.each do |s|
211
- next if File.file? s
212
- wc = count_dict_words(CrypticResolver::Resolver::DEFAULT_LIB_PATH,s)
213
+ next if File.file? path + "/#{s}"
214
+ wc = count_dict_words(path,s)
213
215
  @word_count_of_def_lib += wc
214
216
  # With color, ljust not works, so we disable color
215
217
  puts("#{wc.to_s.rjust(5)} #{s}") if display
@@ -222,12 +224,11 @@ class CrypticResolver::Resolver::Counter
222
224
  # Count extra library
223
225
  def count_extra_lib(display: )
224
226
  if path = @resolver.extra_lib_path
225
- extra_lib = Dir.children(path)
227
+ extra_lib = Dir.children path
226
228
  unless extra_lib.empty?
227
- wc = 0
228
- puts(bold(green("\nExtra library:"))) if display
229
+ puts bold(green("\nExtra library:")) if display
229
230
  extra_lib.each do |s|
230
- next if File.file? s
231
+ next if File.file? path + "/#{s}"
231
232
  wc = count_dict_words(path,s)
232
233
  @word_count_of_extra_lib += wc
233
234
  puts("#{wc.to_s.rjust(5)} #{s}") if display
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cr.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.2
4
+ version: 4.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aoran Zeng
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-13 00:00:00.000000000 Z
11
+ date: 2023-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tomlrb
@@ -71,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  - !ruby/object:Gem::Version
72
72
  version: '0'
73
73
  requirements: []
74
- rubygems_version: 3.4.1
74
+ rubygems_version: 3.4.8
75
75
  signing_key:
76
76
  specification_version: 4
77
77
  summary: 'cr: Cryptic Resolver'