cr.rb 4.0.0.alpha.3 → 4.0.0.alpha.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/cr +28 -15
  3. data/lib/cr.rb +2 -3
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1cab1b378efd946710c171f3dc45c994c5cc76a3b6672fc25fc696aa017dbb29
4
- data.tar.gz: b7e9b9e5d3834ac18e898e9024cf4573f15197d00cc746f50685ea30f68efc9e
3
+ metadata.gz: b6efedf23b1d4b3539679386e6c0aa5afb823e32e71000d4ad0e743efd46eb1a
4
+ data.tar.gz: ee4a8db242b5783824b1dc63c1515034744db1a50c554c31b8c8102047bc5c1e
5
5
  SHA512:
6
- metadata.gz: f75f57865bd0651a336d2ca553c5745974f892ffa5841fb4a3420efd1714ae1e08835632f77c45f5610002cae1190dc1d9e49c68a46865d576f91b114a56b134
7
- data.tar.gz: 422bc7721e40f6878bea1f47c7781e0a8fa81e982eb9dfd1fdb9e766ea4bca753c84203c231aa96b04c0de083ca711a9c4d738ed94ee08dd79b66084e3b103e7
6
+ metadata.gz: 6f657246ebbdcd609f31ac8c34bb1f91ae339cf708447c6609f3aa298ec90264b3f4c527169750d9d91f47e6041506acea2aaafd602411f816bf2a8333010cbd
7
+ data.tar.gz: be590e4d9a10d9ea0371b8df3a48aa1da9d822a5f46000d6b145abdb1391232d8a15b48278af1aead6c7c69fd0ad0dc5b53a9f489961d5f99f909d9dde530ca3
data/bin/cr CHANGED
@@ -224,7 +224,7 @@ def add_dict(repo)
224
224
 
225
225
  # github/com/ccmywish/ruby_knowledge(.git)
226
226
  dict = repo.split('/')[-1].delete_suffix('.git')
227
- count_dict_words(dict)
227
+ count_dict_words(CR_DEFAULT_LIBRARY ,dict)
228
228
  puts
229
229
  puts "#$TwoLibWordCount words added"
230
230
 
@@ -570,18 +570,35 @@ NotFound
570
570
  end
571
571
 
572
572
 
573
+ #
574
+ # Delegate to `search_word_internal`
575
+ #
576
+ def search_word(pattern)
577
+ found_or_not1 = false
578
+ found_or_not2 = false
579
+
580
+ found_or_not1 = search_word_internal(pattern, CR_DEFAULT_LIBRARY)
581
+ if CR_EXTRA_LIBRARY
582
+ found_or_not2 = search_word_internal(pattern, CR_EXTRA_LIBRARY)
583
+ end
584
+
585
+ if (found_or_not1 == false) && (found_or_not2 == false)
586
+ puts red("cr: No words match with #{pattern.inspect}")
587
+ puts
588
+ end
589
+ end
573
590
 
574
591
  #
575
- # This `search_word` routine is quite like `resolve_word`
592
+ # This `search_word_internal` routine is quite like `resolve_word`
576
593
  # Notice:
577
594
  # We handle two cases
578
595
  #
579
596
  # 1. the 'pattern' is the regexp itself
580
- # 2. the 'pattern' is like '/blahblah/'
597
+ # 2. the 'pattern' is like '/blah/'
581
598
  #
582
599
  # The second is what Ruby and Perl users like to do, handle it!
583
600
  #
584
- def search_word(pattern)
601
+ def search_word_internal(pattern, library)
585
602
 
586
603
  if pattern.nil?
587
604
  puts bold(red("cr: Need an argument!"))
@@ -596,24 +613,24 @@ def search_word(pattern)
596
613
  regexp = %r[#{pattern}]
597
614
  end
598
615
 
599
- found = false
616
+ found_or_not = false
600
617
 
601
618
  #
602
619
  # Try to match every word in all dicts
603
620
  #
604
- Dir.children(CR_DEFAULT_LIBRARY).each do |dict|
605
- sheets = Dir.children(File.join(CR_DEFAULT_LIBRARY, dict)).select do
621
+ Dir.children(library).each do |dict|
622
+ sheets = Dir.children(File.join(library, dict)).select do
606
623
  _1.end_with?('.toml')
607
624
  end
608
625
 
609
626
  similar_words_in_a_dict = []
610
627
 
611
628
  sheets.each do |sheet|
612
- sheet_content = load_sheet(dict, File.basename(sheet,'.toml'))
629
+ sheet_content = load_sheet(library, dict, File.basename(sheet,'.toml'))
613
630
 
614
631
  sheet_content.keys.each do
615
632
  if _1 =~ regexp
616
- found = true
633
+ found_or_not = true
617
634
  similar_words_in_a_dict << _1
618
635
  end
619
636
  end
@@ -629,10 +646,7 @@ def search_word(pattern)
629
646
  puts
630
647
  end
631
648
  end
632
- if !found
633
- puts red("cr: No words match with #{regexp.inspect}")
634
- puts
635
- end
649
+ return found_or_not
636
650
  end
637
651
 
638
652
 
@@ -784,5 +798,4 @@ when '--help'
784
798
  help
785
799
  else
786
800
  resolve_word arg
787
- end
788
-
801
+ end
data/lib/cr.rb CHANGED
@@ -10,7 +10,7 @@
10
10
  #
11
11
  # ------------------------------------------------------
12
12
 
13
- CR_GEM_VERSION = "4.0.0.alpha.3"
13
+ CR_GEM_VERSION = "4.0.0.alpha.5"
14
14
 
15
15
 
16
16
  CR_OFFICIAL_DICTS = <<-EOF
@@ -24,5 +24,4 @@ Field:
24
24
 
25
25
  Specific:
26
26
  dos x86 signal
27
-
28
- EOF
27
+ EOF
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.0.0.alpha.3
4
+ version: 4.0.0.alpha.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - ccmywish