remoji 0.1.7 → 0.2.0

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/README.adoc +6 -6
  3. data/lib/remoji.rb +42 -35
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ae3aea0a8f9827bddb9c49ed0d859624e4103f3632e210c7836127abc610074
4
- data.tar.gz: 63f467ac5b178839e00d096658da9d5351cc0d20e8ccbe3a158c07ac57a35ff4
3
+ metadata.gz: d8726b1419bb4466309d2cba91ebed4da62334560a09690d091e5136cd5b2b8c
4
+ data.tar.gz: e582403321f9c4d462f541d924d021c4d8760b82a91c3fe903bfbc6ce6ced7f4
5
5
  SHA512:
6
- metadata.gz: 8521de7667461162c1b29a37aca3f3d474f382ac19aff9abd3109255ade26222bfd5868d70dbae6b88d807cdb9932184dd540df6afd97da1e9aea50d8dab760e
7
- data.tar.gz: 0d449ec0292aff89802512fa8edcfd3ba7c3aa0829d291ec0d41690f15e4ee2e8f76c803e0dd3bbc7f204d3936f9647b211aa571a6bf866e7f2660a80937f45e
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 Just print the emojis
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 without any metadata (-n)
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 S:The blue S:Cow cow
77
- The 💙 📘 🔵 🟦 🔷 🔹 Cow 🤠 🐮 🐄
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! args
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
- def initialize
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!(args)
112
+ def execute!
111
113
  parse_opts! args
112
-
113
114
  if args.empty?
114
- output filter_array
115
+ puts output(filter_array)
115
116
  exit
116
117
  end
117
118
 
118
- found = []
119
- args.each do |arg|
120
- found << if arg.match?(/^S:/)
121
- arg
122
- else
123
- find_in_filter_array(arg)
124
- end
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
- output found.compact.flatten 1
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__
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remoji
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tj@rubyists.com