cr.rb 3.21.0 → 4.0.0.alpha.1

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/cr +178 -131
  3. data/lib/cr.rb +18 -3
  4. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e25ab95484c9ca0c70ca4ebbbdf0c6f01f975930e66c552424f5ba12a9e2a1f4
4
- data.tar.gz: ebf0410ef786f36f870fa2289d764593a1e50778e192861e87048fa01fdd4c1e
3
+ metadata.gz: cf84244ffcf5db536a394a4c7c6ad9679485be53d56baf821bca8a228dd4241b
4
+ data.tar.gz: 13393a7e9fd9e86d021ef39e830de56ffa548c8159cf172af61c6631e1d2ee93
5
5
  SHA512:
6
- metadata.gz: 4a7aed4be85c661e46c58d326755de0e7d1a249a3e71834895fabee604f0a63a7ea6261f0fd9384247028fcdf51f879c17c28243c4ae5ed118311dc3b171dea5
7
- data.tar.gz: ae53f3a4ea09ba563693a781b96dd21dee0f3d5ded483db2c05ff0a07f5ddd02ebe6520fa70683aeb6eb1b3595fff122ec6ce4ceedc797c2f36e2d125dc1a832
6
+ metadata.gz: f0e9316fb7d0e073600e815292c6ef3279cec61275a94ded64ddde456784027eb15d62c239ce953f1036212a8429546240af33bba371667d3f4958a71c823afb
7
+ data.tar.gz: fa316a2e6003409ba527d7ebb86ba474ebc97a3982e79826ed117a4c52b0bb6b3cfaf9b254c135db44484e9faaaee43d7fe6c956dd536dc234a934b38cf3ddc2
data/bin/cr CHANGED
@@ -4,7 +4,7 @@
4
4
  # File : cr.rb
5
5
  # Authors : ccmywish <ccmywish@qq.com>
6
6
  # Created on : <2021-07-08>
7
- # Last modified : <2022-10-30>
7
+ # Last modified : <2022-11-27>
8
8
  #
9
9
  # cr:
10
10
  #
@@ -18,14 +18,53 @@ require 'cr'
18
18
  require 'tomlrb'
19
19
  require 'fileutils'
20
20
 
21
- CRYPTIC_RESOLVER_HOME = File.expand_path("~/.cryptic-resolver")
22
- CRYPTIC_DEFAULT_DICTS = {
23
- common: "https://github.com/cryptic-resolver/cryptic_common.git",
24
- computer: "https://github.com/cryptic-resolver/cryptic_computer.git",
25
- windows: "https://github.com/cryptic-resolver/cryptic_windows.git",
26
- linux: "https://github.com/cryptic-resolver/cryptic_linux.git",
27
- electronics: "https://github.com/cryptic-resolver/cryptic_electronics.git"
28
- }
21
+ CR_DEFAULT_LIBRARY = File.expand_path("~/.cryptic-resolver")
22
+
23
+ $CR_DEFAULT_DICTS = [
24
+ "https://github.com/cryptic-resolver/cryptic_common.git",
25
+ "https://github.com/cryptic-resolver/cryptic_computer.git",
26
+ "https://github.com/cryptic-resolver/cryptic_windows.git",
27
+ "https://github.com/cryptic-resolver/cryptic_linux.git",
28
+ "https://github.com/cryptic-resolver/cryptic_electronics"
29
+ ]
30
+
31
+ # The config file will override the default dicts, but not default library!
32
+ if ENV['CRYPTIC_RESOLVER_CONFIG']
33
+ file = ENV['CRYPTIC_RESOLVER_CONFIG']
34
+ if test('f', file)
35
+ config = Tomlrb.load_file file
36
+
37
+ CR_EXTRA_LIBRARY ||= config['EXTRA_LIBRARY']
38
+
39
+ if config['DEFAULT_DICTS']
40
+ CR_DEFAULT_DICTS = config['DEFAULT_DICTS']
41
+ else
42
+ CR_DEFAULT_DICTS = $CR_DEFAULT_DICTS
43
+ end
44
+
45
+ else
46
+ puts "FATAL: Your CRYPTIC_RESOLVER_CONFIG is NOT a file!"
47
+ exit 1
48
+ end
49
+
50
+ else
51
+ # if user doesn't specify, we use the hard-coded defaults
52
+ CR_EXTRA_LIBRARY = nil
53
+ CR_DEFAULT_DICTS = $CR_DEFAULT_DICTS
54
+ end
55
+
56
+
57
+ # This is used to display what you are pulling when adding dicts
58
+ CR_DEFAULT_DICTS_USER_AND_NAMES = CR_DEFAULT_DICTS.map do |e|
59
+ user, repo = e.split('/').last(2)
60
+ repo = repo.split('.').first
61
+ user + '/' + repo
62
+ end
63
+
64
+ # Same with the pulled repo dirs' names in CR_DEFAULT_LIBRARY
65
+ CR_DEFAULT_DICTS_NAMES = CR_DEFAULT_DICTS.map do |e|
66
+ e.split('/').last.split('.').first
67
+ end
29
68
 
30
69
 
31
70
  ####################
@@ -47,31 +86,31 @@ def cyan(str) "\e[36m#{str}\e[0m" end
47
86
  ####################
48
87
 
49
88
  def is_there_any_dict?
50
- unless Dir.exist? CRYPTIC_RESOLVER_HOME
51
- Dir.mkdir CRYPTIC_RESOLVER_HOME
89
+ unless Dir.exist? CR_DEFAULT_LIBRARY
90
+ Dir.mkdir CR_DEFAULT_LIBRARY
52
91
  end
53
92
 
54
- !Dir.empty? CRYPTIC_RESOLVER_HOME
93
+ !Dir.empty? CR_DEFAULT_LIBRARY
55
94
  end
56
95
 
57
96
 
58
97
  def add_default_dicts_if_none_exists
59
98
  unless is_there_any_dict?
60
- puts "cr: Adding default dictionaries..."
99
+ puts "cr: Adding default dicts..."
61
100
 
62
101
  begin
63
102
  if RUBY_PLATFORM.include? "mingw"
64
103
  # Windows doesn't have fork
65
- CRYPTIC_DEFAULT_DICTS.each do |key, dict|
66
- puts "cr: Pulling cryptic_#{key}..."
67
- `git -C #{CRYPTIC_RESOLVER_HOME} clone #{dict} -q`
104
+ CR_DEFAULT_DICTS_USER_AND_NAMES.each_with_index do |name, i|
105
+ puts "cr: Pulling #{name}..."
106
+ `git -C #{CR_DEFAULT_LIBRARY} clone #{CR_DEFAULT_DICTS[i]} -q`
68
107
  end
69
108
  else
70
- # *nix
71
- CRYPTIC_DEFAULT_DICTS.each do |key, dict|
109
+ # *nix-like
110
+ CR_DEFAULT_DICTS_USER_AND_NAMES.each_with_index do |name, i|
72
111
  fork do
73
- puts "cr: Pulling cryptic_#{key}..."
74
- `git -C #{CRYPTIC_RESOLVER_HOME} clone #{dict} -q`
112
+ puts "cr: Pulling #{name}..."
113
+ `git -C #{CR_DEFAULT_LIBRARY} clone #{CR_DEFAULT_DICTS[i]} -q`
75
114
  end
76
115
  end
77
116
  Process.waitall
@@ -85,7 +124,7 @@ def add_default_dicts_if_none_exists
85
124
  puts "cr: Add done"
86
125
  word_count(p: false)
87
126
  puts
88
- puts "#{$WordCount} words added"
127
+ puts "#{$TwoLibWordCount} words added"
89
128
 
90
129
  # Really added
91
130
  return true
@@ -95,26 +134,27 @@ def add_default_dicts_if_none_exists
95
134
  end
96
135
 
97
136
 
137
+ # Notice that we only update the Default library, not Extra library
98
138
  def update_dicts()
99
139
  return if add_default_dicts_if_none_exists
100
140
 
101
141
  word_count(p: false)
102
- old_wc = [$DefaultWordCount, $WordCount-$DefaultWordCount, $WordCount]
142
+ old_wc = $DefaultLibWordCount
103
143
 
104
- puts "cr: Updating all dictionaries..."
144
+ puts "cr: Updating all dicts in Default library..."
105
145
 
106
146
  begin
107
- Dir.chdir CRYPTIC_RESOLVER_HOME do
147
+ Dir.chdir CR_DEFAULT_LIBRARY do
108
148
 
109
149
  if RUBY_PLATFORM.include? "mingw"
110
150
  # Windows doesn't have fork
111
- Dir.children(CRYPTIC_RESOLVER_HOME).each do |dict|
151
+ Dir.children(CR_DEFAULT_LIBRARY).each do |dict|
112
152
  puts "cr: Wait to update #{dict}..."
113
153
  `git -C ./#{dict} pull -q`
114
154
  end
115
155
  else
116
156
  # *nix
117
- Dir.children(CRYPTIC_RESOLVER_HOME).each do |dict|
157
+ Dir.children(CR_DEFAULT_LIBRARY).each do |dict|
118
158
  fork do
119
159
  puts "cr: Wait to update #{dict}..."
120
160
  `git -C ./#{dict} pull -q`
@@ -130,21 +170,17 @@ def update_dicts()
130
170
  exit 1
131
171
  end
132
172
 
133
-
134
173
  puts "cr: Update done"
135
174
 
136
175
  # clear
137
- $DefaultWordCount, $WordCount = 0, 0
176
+ $DefaultLibWordCount = 0
138
177
  # recount
139
178
  word_count(p: false)
140
- new_wc = [$DefaultWordCount, $WordCount-$DefaultWordCount, $WordCount]
141
- diff = []
142
- new_wc.each_with_index do
143
- diff[_2] = _1 - old_wc[_2]
144
- end
179
+
180
+ new_wc = $DefaultLibWordCount
145
181
 
146
182
  puts
147
- puts "#{diff.[]2} words added: default/#{diff.[]0} user/#{diff.[]1}"
183
+ puts "#{new_wc - old_wc} words added in Default library"
148
184
 
149
185
  end
150
186
 
@@ -156,16 +192,20 @@ def add_dict(repo)
156
192
  end
157
193
 
158
194
  # Ensure the cr home dir exists
159
- FileUtils.mkdir_p(CRYPTIC_RESOLVER_HOME)
195
+ FileUtils.mkdir_p(CR_DEFAULT_LIBRARY)
160
196
 
161
197
  # Simplify adding dictionary
162
198
  if !repo.start_with?("https://") and !repo.start_with?("git@")
163
- repo = "https://github.com/#{repo}.git"
199
+ if repo.include?('/')
200
+ repo = "https://github.com/#{repo}.git"
201
+ else
202
+ repo = "https://github.com/cryptic-resolver/cryptic_#{repo}.git"
203
+ end
164
204
  end
165
205
 
166
206
  begin
167
207
  puts "cr: Adding new dictionary..."
168
- `git -C #{CRYPTIC_RESOLVER_HOME} clone #{repo} -q`
208
+ `git -C #{CR_DEFAULT_LIBRARY} clone #{repo} -q`
169
209
  rescue Interrupt
170
210
  puts "cr: Cancel add dict"
171
211
  exit 1
@@ -177,7 +217,7 @@ def add_dict(repo)
177
217
  dict = repo.split('/')[-1].delete_suffix('.git')
178
218
  count_dict_words(dict)
179
219
  puts
180
- puts "#$WordCount words added"
220
+ puts "#$TwoLibWordCount words added"
181
221
 
182
222
  end
183
223
 
@@ -187,7 +227,7 @@ def del_dict(repo)
187
227
  puts bold(red("cr: Need an argument!"))
188
228
  exit -1
189
229
  end
190
- Dir.chdir CRYPTIC_RESOLVER_HOME do
230
+ Dir.chdir CR_DEFAULT_LIBRARY do
191
231
  begin
192
232
  # Dir.rmdir repo # Can't rm a filled dir
193
233
  # FileUtils.rmdir repo # Can't rm a filled dir
@@ -195,14 +235,14 @@ def del_dict(repo)
195
235
  puts "cr: Delete dictionary #{bold(green(repo))} done"
196
236
  rescue Exception => e
197
237
  puts bold(red("cr: #{e}"))
198
- list_dictionaries
238
+ list_dicts
199
239
  end
200
240
  end
201
241
  end
202
242
 
203
243
 
204
- def load_sheet(dict, sheet_name)
205
- file = CRYPTIC_RESOLVER_HOME + "/#{dict}/#{sheet_name}.toml"
244
+ def load_sheet(library, dict, sheet_name)
245
+ file = library + "/#{dict}/#{sheet_name}.toml"
206
246
 
207
247
  if File.exist? file
208
248
  return Tomlrb.load_file file # gem 'tomlrb'
@@ -252,7 +292,7 @@ def pp_info(info)
252
292
  puts
253
293
  end
254
294
 
255
- # Print default cryptic_ dictionaries
295
+ # Print default cryptic_ dicts
256
296
  def pp_dict(dict)
257
297
  puts green("From: #{dict}")
258
298
  end
@@ -280,7 +320,7 @@ end
280
320
  # same = "XDG downloader <=>xdg.Download" # this is correct
281
321
  #
282
322
  #
283
- def pp_same_info(dict, word, cache_content, same_key, own_name)
323
+ def pp_same_info(library, dict, word, cache_content, same_key, own_name)
284
324
 
285
325
  # If it's a synonym for anther word,
286
326
  # we should lookup into this dict again, but maybe with a different file
@@ -337,7 +377,7 @@ def pp_same_info(dict, word, cache_content, same_key, own_name)
337
377
  # No need to load another dictionary if match
338
378
  sheet_content = cache_content
339
379
  else
340
- sheet_content = load_sheet(dict, same.chr.downcase)
380
+ sheet_content = load_sheet(library, dict, same.chr.downcase)
341
381
  end
342
382
 
343
383
  if category.nil?
@@ -354,7 +394,7 @@ def pp_same_info(dict, word, cache_content, same_key, own_name)
354
394
  # double or more jumps
355
395
  elsif same_key = info['same']
356
396
  own_name = info['name']
357
- return pp_same_info(dict, same, cache_content, same_key, own_name)
397
+ return pp_same_info(library, dict, same, cache_content, same_key, own_name)
358
398
  else
359
399
  pp_info(info)
360
400
  return true
@@ -376,8 +416,8 @@ end
376
416
  # 2.2 with category specifier
377
417
  # [abcd.tYPe]
378
418
  #
379
- def lookup(dict, file, word)
380
- sheet_content = load_sheet(dict, file)
419
+ def lookup(library, dict, file, word)
420
+ sheet_content = load_sheet(library, dict, file)
381
421
  return false if sheet_content.nil?
382
422
 
383
423
  info = sheet_content[word]
@@ -392,7 +432,6 @@ def lookup(dict, file, word)
392
432
  end
393
433
 
394
434
 
395
-
396
435
  # Word with no category specifier
397
436
  # We call this meaning as type 1
398
437
  type_1_exist_flag = false
@@ -404,7 +443,7 @@ def lookup(dict, file, word)
404
443
  if same_key = info['same']
405
444
  own_name = info['name']
406
445
  pp_dict(dict)
407
- pp_same_info(dict, word, sheet_content, same_key, own_name)
446
+ pp_same_info(library, dict, word, sheet_content, same_key, own_name)
408
447
  # It's also a type 1
409
448
  type_1_exist_flag = true
410
449
  is_jump = true
@@ -441,7 +480,7 @@ def lookup(dict, file, word)
441
480
  info0 = sheet_content[word][meaning]
442
481
  if same_key = info0['same']
443
482
  own_name = info0['name']
444
- pp_same_info(dict, word, sheet_content, same_key, own_name)
483
+ pp_same_info(library, dict, word, sheet_content, same_key, own_name)
445
484
  else
446
485
  pp_info(info0)
447
486
  end
@@ -460,15 +499,16 @@ end
460
499
 
461
500
  #
462
501
  # The main procedure of `cr`
463
- # 1. Search the default's first dict first
464
- # 2. Search the rest dictionaries in the cryptic dictionaries default dir
502
+ #
503
+ # 1. Search the default library first
504
+ # 2. Search the extra library if it does exist
465
505
  #
466
506
  # The `search` is done via the `lookup` function. It will print
467
507
  # the info while finding. If `lookup` always return false then
468
- # means lacking of this word in our dictionaries. So a welcomed
508
+ # means lacking of this word in our dicts. So a welcomed
469
509
  # contribution is printed on the screen.
470
510
  #
471
- def solve_word(word)
511
+ def resolve_word(word)
472
512
 
473
513
  add_default_dicts_if_none_exists
474
514
 
@@ -479,21 +519,22 @@ def solve_word(word)
479
519
  when '0'..'9'
480
520
  index = '0123456789'
481
521
  end
482
-
483
- # Default's first should be 1st to consider
484
- first_dict = "cryptic_" + CRYPTIC_DEFAULT_DICTS.keys[0].to_s # When Ruby3, We can use DICTS.key(0)
485
522
 
486
- # cache lookup results
523
+ # cache lookup's results
487
524
  results = []
488
- results << lookup(first_dict,index,word)
489
- # return if result == true # We should consider all dicts
490
-
491
- # Then else
492
- rest = Dir.children(CRYPTIC_RESOLVER_HOME)
493
- rest.delete first_dict
494
- rest.each do |dict|
495
- results << lookup(dict,index,word)
496
- # continue if result == false # We should consider all dicts
525
+
526
+ # First consider the default library
527
+ default = Dir.children(CR_DEFAULT_LIBRARY)
528
+ default.each do |dict|
529
+ results << lookup(CR_DEFAULT_LIBRARY,dict,index,word)
530
+ end
531
+
532
+ # Then is the extra library
533
+ if CR_EXTRA_LIBRARY
534
+ extra = Dir.children(CR_EXTRA_LIBRARY)
535
+ extra.each do |dict|
536
+ results << lookup(CR_EXTRA_LIBRARY,dict,index,word)
537
+ end
497
538
  end
498
539
 
499
540
  unless results.include? true
@@ -519,7 +560,7 @@ end
519
560
 
520
561
 
521
562
  #
522
- # The search word process is quite like `solve_word``
563
+ # This `search_word` routine is quite like `resolve_word`
523
564
  # Notice:
524
565
  # We handle two cases
525
566
  #
@@ -546,10 +587,10 @@ def search_word(pattern)
546
587
  found = false
547
588
 
548
589
  #
549
- # Try to match every word in all dictionaries
590
+ # Try to match every word in all dicts
550
591
  #
551
- Dir.children(CRYPTIC_RESOLVER_HOME).each do |dict|
552
- sheets = Dir.children(File.join(CRYPTIC_RESOLVER_HOME, dict)).select do
592
+ Dir.children(CR_DEFAULT_LIBRARY).each do |dict|
593
+ sheets = Dir.children(File.join(CR_DEFAULT_LIBRARY, dict)).select do
553
594
  _1.end_with?('.toml')
554
595
  end
555
596
 
@@ -585,19 +626,21 @@ end
585
626
 
586
627
  def help
587
628
  word_count(p: false)
588
- user_words = $WordCount - $DefaultWordCount
589
629
  puts <<-HELP
590
- cr: Cryptic Resolver v#{CR_GEM_VERSION} (#{$WordCount} words: default/#{$DefaultWordCount} user/#{user_words})
630
+ cr: Cryptic Resolver v#{CR_GEM_VERSION} (#{$TwoLibWordCount} words: Default lib/#{$DefaultLibWordCount} && Extra lib/#{$ExtraLibWordCount})
591
631
 
592
- usage:
632
+ Usage:
593
633
 
594
- cr emacs => Edit macros: a feature-rich editor
634
+ cr emacs => Edit macros: A feature-rich editor
595
635
  cr -c => Print word count
596
- cr -l => List local dictionaries
597
- cr -u => Update all dictionaries
598
- cr -a repo.git => Add a new dictionary
599
- cr -a user/repo => Add a new dictionary on Github
600
- cr -d cryptic_xx => Delete a dictionary
636
+ cr -l => List local dicts and official dicts
637
+ cr -u => Update all dicts in default library
638
+
639
+ cr -a repo.git => Add a new dict
640
+ cr -a user/repo => Add a new dict from Github
641
+ cr -a reponame => Add an official dict from Github
642
+
643
+ cr -d cryptic_xx => Delete a dict
601
644
  cr -s pattern => Search words matched with pattern
602
645
  cr -v => Print version
603
646
  cr -h => Print this help
@@ -614,91 +657,95 @@ def print_version
614
657
  end
615
658
 
616
659
 
617
- def list_dictionaries
618
- Dir.chdir CRYPTIC_RESOLVER_HOME do
619
- Dir.children(CRYPTIC_RESOLVER_HOME).each_with_index do |dict,i|
660
+ #
661
+ # 1. List Default library's dicts
662
+ # 2. List Extra library's dicts
663
+ # 3. List official dicts
664
+ #
665
+ def list_dicts
666
+ Dir.chdir CR_DEFAULT_LIBRARY do
667
+ puts blue("=> Default library: #{CR_DEFAULT_LIBRARY}")
668
+ Dir.children(CR_DEFAULT_LIBRARY).each_with_index do |dict,i|
620
669
  puts "#{blue(i+1)}. #{bold(green(dict))}"
621
670
  end
622
671
  end
672
+
673
+ if CR_EXTRA_LIBRARY
674
+ puts
675
+ Dir.chdir CR_EXTRA_LIBRARY do
676
+ puts blue("=> Extra library: #{CR_EXTRA_LIBRARY}")
677
+ Dir.children(CR_EXTRA_LIBRARY).each_with_index do |dict,i|
678
+ puts "#{blue(i+1)}. #{bold(green(dict))}"
679
+ end
680
+ end
681
+ end
682
+
683
+ puts
684
+ puts blue("=> Official dicts: (Add it by 'cr -a xxx')")
685
+ puts CR_OFFICIAL_DICTS
686
+
623
687
  end
624
688
 
625
689
 
626
- # All dictionaries word count
627
- $WordCount = 0
628
- # Default dictionaries word count
629
- $DefaultWordCount = 0
690
+ # Two libraries word count (Default library + Extra library)
691
+ $TwoLibWordCount = 0
692
+ # Default library word count
693
+ $DefaultLibWordCount = 0
694
+ # Extra library word count
695
+ $ExtraLibWordCount = 0
630
696
 
631
- def count_dict_words(dict)
697
+ def count_dict_words(library, dict)
632
698
 
633
- dict_dir = CRYPTIC_RESOLVER_HOME + "/#{dict}"
699
+ dict_dir = library + "/#{dict}"
634
700
 
635
701
  wc = 0
636
702
 
637
703
  Dir.children(dict_dir).each do |entry|
638
704
  next unless entry.end_with?('.toml')
639
- sheet_content = load_sheet(dict, entry.delete_suffix('.toml'))
705
+ sheet_content = load_sheet(library, dict, entry.delete_suffix('.toml'))
640
706
  count = sheet_content.keys.count
641
-
642
- # puts "#{entry}: #{count}"
707
+
643
708
  wc = wc + count
644
709
  end
645
-
646
- $WordCount += wc
647
-
648
710
  return wc
649
-
650
711
  end
651
712
 
652
713
 
653
714
  def word_count(p:)
654
-
655
715
  # Always check before Dir.children (this method creates dir if not exists)
656
716
  is_there_any_dict?
657
717
 
658
- # real dicts in user's directory
659
- locals = []
660
- Dir.children(CRYPTIC_RESOLVER_HOME).each do |dict|
661
- locals << dict
662
- end
663
-
664
- # pre-defined default
665
- defaults = CRYPTIC_DEFAULT_DICTS.keys.map do |s|
666
- "cryptic_#{s}"
667
- end
668
-
669
- # user may delete some default dicts
670
- defaults &= locals
718
+ default_lib = Dir.children(CR_DEFAULT_LIBRARY)
719
+ extra_lib = Dir.children(CR_EXTRA_LIBRARY)
671
720
 
672
- unless defaults.empty?
673
- puts(bold(green("Default dicts: "))) if p
674
- defaults.each do |s|
675
- wc = count_dict_words(s)
676
- $DefaultWordCount += wc
721
+ # Count default library
722
+ unless default_lib.empty?
723
+ puts(bold(green("Default library: "))) if p
724
+ default_lib.each do |s|
725
+ wc = count_dict_words(CR_DEFAULT_LIBRARY,s)
726
+ $DefaultLibWordCount += wc
677
727
  # With color, ljust not works, so we disable color
678
728
  puts(" #{s.ljust(17)}: #{wc}") if p
679
729
  end
680
730
  end
681
731
 
682
- users = locals - defaults
683
- user_words = 0
684
- unless users.empty?
732
+ # Count extra library
733
+ unless extra_lib.empty?
685
734
  wc = 0
686
- puts(bold(blue("\nUser's dict:"))) if p
687
- users.each do |s|
688
- wc = count_dict_words(s)
689
- # no need to add to $WordCount,
690
- # because it's done in `count_dict_words` func
735
+ puts(bold(blue("\nExtra library:"))) if p
736
+ extra_lib.each do |s|
737
+ wc = count_dict_words(CR_EXTRA_LIBRARY,s)
738
+ $ExtraLibWordCount += wc
691
739
  puts(" #{s.ljust(17)}: #{wc}") if p
692
740
  end
693
-
694
- user_words = $WordCount - $DefaultWordCount
741
+ $TwoLibWordCount = $DefaultLibWordCount + $ExtraLibWordCount
695
742
  end
696
743
 
697
744
  if p
698
745
  puts
699
- puts "#{$DefaultWordCount.to_s.rjust(4)} words in default dictionaries"
700
- puts "#{user_words.to_s.rjust(4)} words in user's dictionaries"
701
- puts "#{$WordCount.to_s.rjust(4)} words altogether"
746
+ puts "#{$DefaultLibWordCount.to_s.rjust(4)} words in Default library"
747
+ puts "#{$ExtraLibWordCount.to_s.rjust(4) } words in Extra library"
748
+ puts "#{$TwoLibWordCount.to_s.rjust(4) } words altogether"
702
749
  end
703
750
  end
704
751
 
@@ -712,7 +759,7 @@ case arg
712
759
  when nil then help
713
760
  when '-v' then print_version
714
761
  when '-h' then help
715
- when '-l' then list_dictionaries
762
+ when '-l' then list_dicts
716
763
  when '-c' then word_count(p: true)
717
764
  when '-u' then update_dicts
718
765
  when '-s' then search_word ARGV.shift
@@ -721,6 +768,6 @@ when '-d' then del_dict ARGV.shift
721
768
  when '--help'
722
769
  help
723
770
  else
724
- solve_word arg
771
+ resolve_word arg
725
772
  end
726
773
 
data/lib/cr.rb CHANGED
@@ -2,12 +2,27 @@
2
2
  # File : cr.rb
3
3
  # Authors : ccmywish <ccmywish@qq.com>
4
4
  # Created on : <2022-04-15>
5
- # Last modified : <2022-10-30>
5
+ # Last modified : <2022-11-27>
6
6
  #
7
7
  # cr:
8
8
  #
9
- # This file is just a lib
9
+ # This file is the lib of `cr.rb``
10
10
  #
11
11
  # ------------------------------------------------------
12
12
 
13
- CR_GEM_VERSION = "3.21.0"
13
+ CR_GEM_VERSION = "4.0.0.alpha.1"
14
+
15
+
16
+ CR_OFFICIAL_DICTS = <<-EOF
17
+ Default:
18
+ common computer windows
19
+ linux electronics
20
+
21
+ Field:
22
+ economy medicine math
23
+ mechanical science
24
+
25
+ Specific:
26
+ dos x86 signal
27
+
28
+ EOF
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: 3.21.0
4
+ version: 4.0.0.alpha.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ccmywish
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-30 00:00:00.000000000 Z
11
+ date: 2022-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tomlrb
@@ -66,9 +66,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
66
66
  version: '0'
67
67
  required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  requirements:
69
- - - ">="
69
+ - - ">"
70
70
  - !ruby/object:Gem::Version
71
- version: '0'
71
+ version: 1.3.1
72
72
  requirements: []
73
73
  rubygems_version: 3.3.7
74
74
  signing_key: