cr.rb 3.20.0 → 4.0.0.alpha.1

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