cr.rb 4.1.4 → 4.1.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.
- checksums.yaml +4 -4
- data/exe/cr +67 -0
- data/lib/cr/counter.rb +106 -0
- data/lib/cr/version.rb +3 -3
- data/lib/cr.rb +530 -117
- metadata +20 -5
- data/bin/cr +0 -597
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1f71eca516d37dabb6a73e90451407b6c936b2d0139b2b6b92fbadd07005454
|
4
|
+
data.tar.gz: ddedd7585a404db9aa922b829ffc359eaa10162fc950077fff5bec427905539a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bd500805cde6c9b3a28edd6fb0f1209254362f1701871af85f6d8631e5586e653dcb183707caa04c41e7dc54248503a0b420db6358e16397fc3aca623079b6a
|
7
|
+
data.tar.gz: c2e28a15e1e1daf5b8435d01e62c633719eac7cb3e88bca724e13eeaaa1dac483b05bfa360510042b7743c323a33a638ca503f2b1e616e6a431d8622d125fcc3
|
data/exe/cr
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# ------------------------------------------------------
|
3
|
+
# File : cr.rb
|
4
|
+
# Authors : Aoran Zeng <ccmywish@qq.com>
|
5
|
+
# Created on : <2021-07-08>
|
6
|
+
# Last modified : <2023-05-09>
|
7
|
+
#
|
8
|
+
# cr:
|
9
|
+
#
|
10
|
+
# This file is used to explain a CRyptic command
|
11
|
+
# or an acronym's real meaning in computer world or
|
12
|
+
# other fields.
|
13
|
+
# ------------------------------------------------------
|
14
|
+
|
15
|
+
require 'cr'
|
16
|
+
|
17
|
+
module CrypticResolver::CLI
|
18
|
+
|
19
|
+
def self.run
|
20
|
+
args = ARGV.dup
|
21
|
+
|
22
|
+
option = args.shift
|
23
|
+
|
24
|
+
case option when nil, '-h','--help' then help; exit end
|
25
|
+
|
26
|
+
reslvr = CrypticResolver::Resolver.new
|
27
|
+
|
28
|
+
reslvr.add_default_dicts_if_none_exists
|
29
|
+
|
30
|
+
case option
|
31
|
+
when '-l' then reslvr.list_dicts
|
32
|
+
when '-c' then reslvr.word_count
|
33
|
+
when '-u' then reslvr.update_dicts
|
34
|
+
when '-s' then reslvr.search_word args.shift
|
35
|
+
when '-a' then reslvr.add_dict args.shift
|
36
|
+
when '-d' then reslvr.del_dict args.shift
|
37
|
+
else reslvr.resolve_word option end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def self.help
|
42
|
+
puts <<~HELP
|
43
|
+
cr: Cryptic Resolver v#{CrypticResolver::GEM_VERSION}
|
44
|
+
|
45
|
+
Usage:
|
46
|
+
cr <keyword> Search the keyword
|
47
|
+
cr emacs => Edit macros: A feature-rich editor
|
48
|
+
|
49
|
+
Options:
|
50
|
+
-c Print word count
|
51
|
+
-s <pattern> Search words matched with pattern
|
52
|
+
-h Print this help
|
53
|
+
|
54
|
+
Dictionaries:
|
55
|
+
-l List local dicts and official dicts
|
56
|
+
-u Update all dicts in Default library
|
57
|
+
-a <https://repo[.git]> Add a new dict
|
58
|
+
-a <user/repo> Add a new dict from Github
|
59
|
+
-a <dict_name> Add an official dict, use -l to see
|
60
|
+
-d <dict_name> Delete a dict
|
61
|
+
|
62
|
+
HELP
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
CrypticResolver::CLI.run
|
data/lib/cr/counter.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
# ---------------------------------------------------------------
|
2
|
+
# File : counter.rb
|
3
|
+
# Authors : Aoran Zeng <ccmywish@qq.com>
|
4
|
+
# Created on : <2023-05-09>
|
5
|
+
# Last modified : <2023-05-09>
|
6
|
+
#
|
7
|
+
# counter:
|
8
|
+
#
|
9
|
+
# Count words in dictionaries.
|
10
|
+
#
|
11
|
+
# ----------
|
12
|
+
# Changelog:
|
13
|
+
#
|
14
|
+
# <2023-05-09> Moved from lib/cr.rb
|
15
|
+
# ---------------------------------------------------------------
|
16
|
+
|
17
|
+
class CrypticResolver::Resolver::Counter
|
18
|
+
|
19
|
+
attr_accessor :word_count_of_two_libs, # def_lib + extra_lib
|
20
|
+
:word_count_of_def_lib,
|
21
|
+
:word_count_of_extra_lib,
|
22
|
+
|
23
|
+
:resolver
|
24
|
+
|
25
|
+
def initialize(resolver)
|
26
|
+
@word_count_of_two_libs = 0
|
27
|
+
@word_count_of_def_lib = 0
|
28
|
+
@word_count_of_extra_lib = 0
|
29
|
+
@resolver = resolver
|
30
|
+
end
|
31
|
+
|
32
|
+
# a.toml
|
33
|
+
# b.toml
|
34
|
+
# ...
|
35
|
+
def count_dict_words(library, dict)
|
36
|
+
dict_dir = library + "/#{dict}"
|
37
|
+
wc = 0
|
38
|
+
Dir.children(dict_dir).each do |entry|
|
39
|
+
next unless entry.end_with?('.toml')
|
40
|
+
next if File.directory? dict_dir + "/#{entry}"
|
41
|
+
sheet_content = @resolver.load_sheet(library, dict, entry.delete_suffix('.toml'))
|
42
|
+
count = sheet_content.keys.count
|
43
|
+
|
44
|
+
wc = wc + count
|
45
|
+
end
|
46
|
+
return wc
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
# Count default library
|
51
|
+
def count_def_lib(display: )
|
52
|
+
path = CrypticResolver::Resolver::DEFAULT_LIB_PATH
|
53
|
+
default_lib = Dir.children path
|
54
|
+
unless default_lib.empty?
|
55
|
+
puts "Default library: ".bold.green if display
|
56
|
+
default_lib.each do |s|
|
57
|
+
next if File.file? path + "/#{s}"
|
58
|
+
wc = count_dict_words(path,s)
|
59
|
+
@word_count_of_def_lib += wc
|
60
|
+
# With color, ljust not works, so we disable color
|
61
|
+
puts("#{wc.to_s.rjust(5)} #{s}") if display
|
62
|
+
end
|
63
|
+
end
|
64
|
+
return @word_count_of_def_lib
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
# Count extra library
|
69
|
+
def count_extra_lib(display: )
|
70
|
+
if path = @resolver.extra_lib_path
|
71
|
+
extra_lib = Dir.children path
|
72
|
+
unless extra_lib.empty?
|
73
|
+
puts "\nExtra library:".bold.green if display
|
74
|
+
extra_lib.each do |s|
|
75
|
+
next if File.file? path + "/#{s}"
|
76
|
+
wc = count_dict_words(path,s)
|
77
|
+
@word_count_of_extra_lib += wc
|
78
|
+
puts("#{wc.to_s.rjust(5)} #{s}") if display
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
return @word_count_of_extra_lib
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
def count!(display: )
|
87
|
+
count_def_lib(display: display)
|
88
|
+
count_extra_lib(display: display)
|
89
|
+
@word_count_of_two_libs = @word_count_of_def_lib + @word_count_of_extra_lib
|
90
|
+
|
91
|
+
if display
|
92
|
+
puts
|
93
|
+
puts "#{@word_count_of_def_lib.to_s.rjust(4)} words in Default library"
|
94
|
+
puts "#{@word_count_of_extra_lib.to_s.rjust(4) } words in Extra library"
|
95
|
+
puts "#{@word_count_of_two_libs.to_s.rjust(4) } words altogether"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
def reset!
|
101
|
+
@word_count_of_two_libs = 0
|
102
|
+
@word_count_of_def_lib = 0
|
103
|
+
@word_count_of_extra_lib = 0
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
data/lib/cr/version.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# ---------------------------------------------------------------
|
2
2
|
# File : version.rb
|
3
|
-
# Authors :
|
3
|
+
# Authors : Aoran Zeng <ccmywish@qq.com>
|
4
4
|
# Created on : <2023-02-12>
|
5
|
-
# Last modified : <2023-
|
5
|
+
# Last modified : <2023-05-09>
|
6
6
|
#
|
7
7
|
# version:
|
8
8
|
#
|
@@ -11,6 +11,6 @@
|
|
11
11
|
|
12
12
|
module CrypticResolver
|
13
13
|
|
14
|
-
GEM_VERSION = "4.1.
|
14
|
+
GEM_VERSION = "4.1.5"
|
15
15
|
|
16
16
|
end
|