remoji 0.1.7 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +6 -6
- data/lib/remoji.rb +42 -35
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8726b1419bb4466309d2cba91ebed4da62334560a09690d091e5136cd5b2b8c
|
4
|
+
data.tar.gz: e582403321f9c4d462f541d924d021c4d8760b82a91c3fe903bfbc6ce6ced7f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47cc546e38e03e79bd45460562a2dde345461886f0df52e6de4d07bd771cd483d1e98932eb968aa8992bd84a3150dc28c435036d244396170207c2de253039db
|
7
|
+
data.tar.gz: 5486e83886f85ba783c013937764ab91c26d077ece40e4e88840bfa2f96e999f3bf8a5fa147965f6234dded6e3bacf452b8328dcc259d9b6d620ff4266b9bd30
|
data/README.adoc
CHANGED
@@ -39,12 +39,12 @@ must have internet access for this
|
|
39
39
|
----
|
40
40
|
% emj --help
|
41
41
|
|
42
|
-
emj [options] EMOJI ANOTHER_EMOJI ...
|
42
|
+
emj [options] <EMOJI ANOTHER_EMOJI ... | String With :substitutions: (with -n)>
|
43
43
|
|
44
44
|
Where EMOJI is an emoji name to search for
|
45
45
|
-c, --cat CAT Find matches in a category
|
46
46
|
-s, --subcat CAT Find matches in a subcategory
|
47
|
-
-n, --no-details
|
47
|
+
-n, --no-details Treat arguments as a string and subsitute :emoji: blocks
|
48
48
|
--subs, --subcategories List subcategories
|
49
49
|
--cats, --categories List Categories
|
50
50
|
-v, --verbose Increase verbosity
|
@@ -63,18 +63,18 @@ cat face: 🐱
|
|
63
63
|
cat: 🐈
|
64
64
|
----
|
65
65
|
|
66
|
-
Same search
|
66
|
+
Same search using string substitition
|
67
67
|
|
68
68
|
----
|
69
|
-
% emj -n -c Animal cat
|
69
|
+
% emj -n -c Animal :cat:
|
70
70
|
🐱 🐈
|
71
71
|
----
|
72
72
|
|
73
73
|
Using strings inline with emoji with -n
|
74
74
|
|
75
75
|
----
|
76
|
-
% emj -n
|
77
|
-
The
|
76
|
+
% emj -n The :cow: jumped over the :moon:
|
77
|
+
The 🐄 jumped over the 🎑
|
78
78
|
----
|
79
79
|
|
80
80
|
Show all categories / subcategories
|
data/lib/remoji.rb
CHANGED
@@ -14,7 +14,7 @@ class Remoji # rubocop:disable Metrics/ClassLength
|
|
14
14
|
EMOJI_TABLE = 'http://unicode.org/emoji/charts/full-emoji-list.html'.freeze
|
15
15
|
|
16
16
|
def self.run!(args)
|
17
|
-
new.execute!
|
17
|
+
new(args).execute!
|
18
18
|
end
|
19
19
|
|
20
20
|
def categories
|
@@ -64,7 +64,9 @@ class Remoji # rubocop:disable Metrics/ClassLength
|
|
64
64
|
emoji_file.open('w+') { |f| f.puts JSON.pretty_generate(hash) }
|
65
65
|
end
|
66
66
|
|
67
|
-
|
67
|
+
attr_reader :args
|
68
|
+
def initialize(args)
|
69
|
+
@args = args
|
68
70
|
@options = OpenStruct.new verbose: 0
|
69
71
|
verify_cache!
|
70
72
|
end
|
@@ -107,24 +109,48 @@ class Remoji # rubocop:disable Metrics/ClassLength
|
|
107
109
|
end
|
108
110
|
end
|
109
111
|
|
110
|
-
def execute!
|
112
|
+
def execute!
|
111
113
|
parse_opts! args
|
112
|
-
|
113
114
|
if args.empty?
|
114
|
-
output
|
115
|
+
puts output(filter_array)
|
115
116
|
exit
|
116
117
|
end
|
117
118
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
119
|
+
puts output
|
120
|
+
end
|
121
|
+
|
122
|
+
def formatted(name, attrs)
|
123
|
+
return attrs[:sym] if @options.no
|
124
|
+
return "#{name}: #{attrs}" if @options.verbose.positive?
|
125
|
+
|
126
|
+
[attrs[:sym], name].join(' : ')
|
127
|
+
end
|
128
|
+
|
129
|
+
def output(arr = nil)
|
130
|
+
if arr
|
131
|
+
strings = arr.map { |name, attrs| formatted name, attrs }
|
132
|
+
sep = @options.no ? ' ' : "\n"
|
133
|
+
return strings.join(sep)
|
125
134
|
end
|
135
|
+
return replace_emojis args.join(' ') if @options.no
|
136
|
+
|
137
|
+
args.each_with_object([]) do |q, s|
|
138
|
+
s << string_for(q)
|
139
|
+
end.join.squeeze(' ')
|
140
|
+
end
|
141
|
+
|
142
|
+
def string_for(emoji)
|
143
|
+
found = find_in_filter_array(emoji).each_with_object([]) { |f, arr| arr << f }
|
144
|
+
sep = @options.no ? ' ' : "\n"
|
145
|
+
found.each_with_object([]) do |f, s|
|
146
|
+
s << formatted(*f)
|
147
|
+
end.join sep
|
148
|
+
end
|
126
149
|
|
127
|
-
|
150
|
+
def replace_emojis(string)
|
151
|
+
string.gsub(/:[^:]+:/) do |r|
|
152
|
+
string_for r[1..-2]
|
153
|
+
end
|
128
154
|
end
|
129
155
|
|
130
156
|
def find_in_filter_array(arg)
|
@@ -146,8 +172,9 @@ class Remoji # rubocop:disable Metrics/ClassLength
|
|
146
172
|
|
147
173
|
def parse_opts!(args)
|
148
174
|
OptionParser.new do |o|
|
149
|
-
o.banner = "#{$PROGRAM_NAME} [options] EMOJI ANOTHER_EMOJI ..."
|
175
|
+
o.banner = "#{$PROGRAM_NAME} [options] <EMOJI ANOTHER_EMOJI ... | String With :substitutions: (with -n)>"
|
150
176
|
o.separator 'Where EMOJI is an emoji name to search for'
|
177
|
+
o.separator 'With -n, all arguments are treated as a string and :emoji: blocks are replaced with matches, if any'
|
151
178
|
%i[cat subcat details cats subcats verbose exact regex].each do |sym|
|
152
179
|
send "#{sym}_opt".to_sym, o
|
153
180
|
end
|
@@ -193,33 +220,13 @@ class Remoji # rubocop:disable Metrics/ClassLength
|
|
193
220
|
end
|
194
221
|
|
195
222
|
def details_opt(opt)
|
196
|
-
opt.on('-n', '--no-details', 'Just print the emojis') { |_| @options.no = true }
|
223
|
+
opt.on('-n', '--no-details', 'Just print the string with :emojis: substituded') { |_| @options.no = true }
|
197
224
|
end
|
198
225
|
|
199
226
|
def die!(msg, code = 1)
|
200
227
|
warn msg
|
201
228
|
exit code
|
202
229
|
end
|
203
|
-
|
204
|
-
def output(them)
|
205
|
-
puts display(them)
|
206
|
-
end
|
207
|
-
|
208
|
-
def display(them) # rubocop:disab
|
209
|
-
die! 'No matching emojis found', 2 if them.empty?
|
210
|
-
|
211
|
-
join_char = @options.no ? ' ' : "\n"
|
212
|
-
them.map do |name, attrs|
|
213
|
-
attrs ||= { sym: name.split('S:').last, type: 'Raw String' }
|
214
|
-
if @options.no
|
215
|
-
attrs[:sym]
|
216
|
-
elsif @options.verbose.positive?
|
217
|
-
"#{name}: #{attrs}"
|
218
|
-
else
|
219
|
-
[attrs[:sym], name].join(' : ')
|
220
|
-
end
|
221
|
-
end.join(join_char).squeeze(join_char)
|
222
|
-
end
|
223
230
|
end
|
224
231
|
|
225
232
|
Remoji.run! ARGV if $PROGRAM_NAME == __FILE__
|