cr.rb 4.0.0.alpha.3 → 4.0.0.alpha.4

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 +26 -12
  3. data/lib/cr.rb +1 -1
  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: 5c4ff483935b5b1015fb9d412056e041e81fd3fa7b94c47c8b5de8be517f8740
4
+ data.tar.gz: 2a207377d5dc6bf441d3940d5c142965d944ba6f05de3de7053800bd7b59fb29
5
5
  SHA512:
6
- metadata.gz: f75f57865bd0651a336d2ca553c5745974f892ffa5841fb4a3420efd1714ae1e08835632f77c45f5610002cae1190dc1d9e49c68a46865d576f91b114a56b134
7
- data.tar.gz: 422bc7721e40f6878bea1f47c7781e0a8fa81e982eb9dfd1fdb9e766ea4bca753c84203c231aa96b04c0de083ca711a9c4d738ed94ee08dd79b66084e3b103e7
6
+ metadata.gz: ddd0207e0248b713e3304f6c6781b2f186a7ba3bdc02a4a4823e9def133cfd2209d8295987217d1df92733811efc0a2beb09daa904d85305aee97a9955dda146
7
+ data.tar.gz: 51a67072c4631628d6a6f840e819665c2e26309cc62be9d060cc658b5b8eb19b512557c92d8840f56a32e3777211d6c114870a15208403b647bb7147ec4ca418
data/bin/cr CHANGED
@@ -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
 
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.4"
14
14
 
15
15
 
16
16
  CR_OFFICIAL_DICTS = <<-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.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - ccmywish