remoji 0.0.3
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 +7 -0
- data/COPYING +21 -0
- data/bin/emj +3 -0
- data/lib/remoji.rb +166 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5a45eab5da19a5876b07d17ac60cbaade8a494001fbdc9dfdaf7e34e05c7725b
|
4
|
+
data.tar.gz: 32e8b735bba8c8b7c27e2c39378d4ab432eef23c276aa08c35dc93ac5fe1f2c0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e80a6a45c8dde1641995cbc0213a95033f03a8b5222472841e25bdce936ac648bae018e56af8b6249187811c53197d13ec43aa1ee0782ecacda1ebb99f8fe45d
|
7
|
+
data.tar.gz: c1d3b232c4aa3db694367d1b5b8bcbf7840a814b5a11fbbf7a233602f5107f67d7bc016b0320c2768bc7b00f3b97f3c9ff49449f07ff91d7349204c5837dd563
|
data/COPYING
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Remoji - A simple emoji utility
|
2
|
+
|
3
|
+
Copyright (C) 2019 bougyman <bougyman@rubyists.com>
|
4
|
+
|
5
|
+
Wifish is licenced under the WTFPL, the full text is included below.
|
6
|
+
|
7
|
+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
8
|
+
Version 2, December 2004
|
9
|
+
|
10
|
+
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
11
|
+
|
12
|
+
Everyone is permitted to copy and distribute verbatim or modified
|
13
|
+
copies of this license document, and changing it is allowed as long
|
14
|
+
as the name is changed.
|
15
|
+
|
16
|
+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
17
|
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
18
|
+
|
19
|
+
|
20
|
+
0. You just DO WHAT THE FUCK YOU WANT TO.
|
21
|
+
|
data/bin/emj
ADDED
data/lib/remoji.rb
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'fileutils'
|
3
|
+
require 'pathname'
|
4
|
+
require 'optparse'
|
5
|
+
require 'ostruct'
|
6
|
+
require 'json'
|
7
|
+
require 'awesome_print'
|
8
|
+
require 'pry'
|
9
|
+
require 'nokogiri'
|
10
|
+
require 'open-uri'
|
11
|
+
|
12
|
+
require 'json'
|
13
|
+
|
14
|
+
# The Remoji command
|
15
|
+
class Remoji
|
16
|
+
EMOJI_TABLE = 'http://unicode.org/emoji/charts/full-emoji-list.html'.freeze
|
17
|
+
|
18
|
+
def self.run!(args)
|
19
|
+
new.execute! args
|
20
|
+
end
|
21
|
+
|
22
|
+
def categories
|
23
|
+
@categories ||= filter_hash.map { |_k, v| v[:cat] }.uniq
|
24
|
+
end
|
25
|
+
|
26
|
+
def subcategories
|
27
|
+
@subcategories ||= filter_hash.map { |_k, v| v[:subcat] }.uniq
|
28
|
+
end
|
29
|
+
|
30
|
+
def find_medhead(elem)
|
31
|
+
return medhead(elem).text if medhead(elem)
|
32
|
+
|
33
|
+
find_medhead(elem.previous_sibling)
|
34
|
+
end
|
35
|
+
|
36
|
+
def medhead(elem)
|
37
|
+
elem.css('th[class=mediumhead]').empty? ? nil : elem.css('th[class=mediumhead]')
|
38
|
+
end
|
39
|
+
|
40
|
+
def find_bighead(elem)
|
41
|
+
return bighead(elem).text if bighead(elem)
|
42
|
+
|
43
|
+
find_bighead(elem.previous_sibling)
|
44
|
+
end
|
45
|
+
|
46
|
+
def bighead(elem)
|
47
|
+
elem.css('th[class=bighead]').empty? ? nil : elem.css('th[class=bighead]')
|
48
|
+
end
|
49
|
+
|
50
|
+
def emoji_table
|
51
|
+
doc = Nokogiri(open(EMOJI_TABLE).read) # rubocop:disable Security/Open
|
52
|
+
tds = doc.xpath('//table/tr/td')
|
53
|
+
tds.each_slice 15
|
54
|
+
end
|
55
|
+
|
56
|
+
def import_emojis!
|
57
|
+
hash = {}
|
58
|
+
emoji_table.each do |n|
|
59
|
+
hash[n.last.text] = {
|
60
|
+
code: n[1].text,
|
61
|
+
sym: n[2].text,
|
62
|
+
cat: find_bighead(n.last.parent),
|
63
|
+
subcat: find_medhead(n.last.parent)
|
64
|
+
}
|
65
|
+
end
|
66
|
+
emoji_file.open('w+') { |f| f.puts JSON.pretty_generate(hash) }
|
67
|
+
end
|
68
|
+
|
69
|
+
attr_reader :emoji_file
|
70
|
+
def initialize
|
71
|
+
@emoji_file = Pathname('/tmp/emojis.json')
|
72
|
+
@options = OpenStruct.new
|
73
|
+
verify_cache!
|
74
|
+
end
|
75
|
+
|
76
|
+
def verify_cache!
|
77
|
+
return if emoji_file.exist?
|
78
|
+
|
79
|
+
warn "No #{@emoji_file} found. Import?"
|
80
|
+
yn = $stdin.getc
|
81
|
+
raise 'Ok, bailing!' unless yn =~ /^y/i
|
82
|
+
|
83
|
+
warn 'Ok, importing'
|
84
|
+
import_emojis!
|
85
|
+
end
|
86
|
+
|
87
|
+
def filter_hash
|
88
|
+
return @filter_hash if @filter_hash
|
89
|
+
|
90
|
+
db = JSON.parse(emoji_file.read, symbolize_names: true)
|
91
|
+
@filter_hash = if @options.subcat
|
92
|
+
db.select { |_k, v| v[:subcat] =~ /#{@options.subcat}/i }
|
93
|
+
elsif @options.cat
|
94
|
+
db.select { |_k, v| v[:cat] =~ /#{@options.cat}/i }
|
95
|
+
else
|
96
|
+
db
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def execute!(args)
|
101
|
+
parse_opts! args
|
102
|
+
|
103
|
+
if args.empty?
|
104
|
+
output filter_hash, @options
|
105
|
+
exit
|
106
|
+
end
|
107
|
+
|
108
|
+
found = {}
|
109
|
+
args.each do |argv|
|
110
|
+
found.merge!(filter_hash.select { |k, _v| k =~ /#{argv}/i })
|
111
|
+
end
|
112
|
+
|
113
|
+
output found, @options
|
114
|
+
end
|
115
|
+
|
116
|
+
def parse_opts!(args)
|
117
|
+
OptionParser.new do |o|
|
118
|
+
o.banner = "#{$PROGRAM_NAME} [options] EMOJI ANOTHER_EMOJI ..."
|
119
|
+
o.separator 'Where EMOJI is an emoji name to search for'
|
120
|
+
%i[cat subcat details cats subcats].each do |sym|
|
121
|
+
send "#{sym}_opt".to_sym, o
|
122
|
+
end
|
123
|
+
o.on('-h', '--help') do
|
124
|
+
puts o
|
125
|
+
exit
|
126
|
+
end
|
127
|
+
end.parse!(args)
|
128
|
+
end
|
129
|
+
|
130
|
+
def cats_opt(opt)
|
131
|
+
opt.on('--subs', '--subcategories') do
|
132
|
+
ap subcategories
|
133
|
+
exit
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def subcats_opt(opt)
|
138
|
+
opt.on('--cats', '--categories') do
|
139
|
+
ap categories
|
140
|
+
exit
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def subcat_opt(opt)
|
145
|
+
opt.on('-sCAT', '--subcat CAT', 'Find matches in a subcategory') { |s| @options.subcat = s }
|
146
|
+
end
|
147
|
+
|
148
|
+
def cat_opt(opt)
|
149
|
+
opt.on('-cCAT', '--cat CAT', 'Find matches in a category') { |s| @options.cat = s }
|
150
|
+
end
|
151
|
+
|
152
|
+
def details_opt(opt)
|
153
|
+
opt.on('-n', '--no-details', 'Just print the emojis') { |_| @options.no = true }
|
154
|
+
end
|
155
|
+
|
156
|
+
def output(them, options = OpenStruct.new)
|
157
|
+
if options.no
|
158
|
+
puts them.map { |_k, v| v[:sym] }.join(' ')
|
159
|
+
else
|
160
|
+
them.each { |k, v| ap(k => v[:sym]) }
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
Remoji.run! ARGV if $PROGRAM_NAME == __FILE__
|
166
|
+
# vim: set et sts=2 sw=2 ts=2 syntax=ruby foldmethod=syntax:
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: remoji
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- tj@rubyists.com
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-10-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: awesome_print
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.8.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.8.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop-performance
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.4'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.4'
|
55
|
+
description: Search for and show emojis
|
56
|
+
email: tj@rubyists.com
|
57
|
+
executables:
|
58
|
+
- emj
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- COPYING
|
63
|
+
- bin/emj
|
64
|
+
- lib/remoji.rb
|
65
|
+
homepage:
|
66
|
+
licenses: []
|
67
|
+
metadata: {}
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '2'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubygems_version: 3.0.3
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Emojis
|
87
|
+
test_files: []
|