emojidex 0.1.0 → 0.2.0
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/emojidex.gemspec +7 -6
- data/lib/emojidex.rb +9 -1
- data/lib/emojidex/client.rb +53 -0
- data/lib/emojidex/data/categories.rb +42 -42
- data/lib/emojidex/data/category.rb +10 -10
- data/lib/emojidex/data/collection.rb +39 -21
- data/lib/emojidex/data/collection/asset_information.rb +19 -3
- data/lib/emojidex/data/collection/cache.rb +28 -33
- data/lib/emojidex/data/collection/moji_data.rb +13 -11
- data/lib/emojidex/data/collection/static_collection.rb +3 -3
- data/lib/emojidex/data/emoji.rb +54 -37
- data/lib/emojidex/data/emoji/asset_information.rb +86 -3
- data/lib/emojidex/data/extended.rb +2 -2
- data/lib/emojidex/data/utf.rb +2 -2
- data/lib/emojidex/defaults.rb +9 -1
- data/lib/emojidex/env_helper.rb +1 -2
- data/lib/emojidex/service/collection.rb +70 -31
- data/lib/emojidex/service/error.rb +1 -0
- data/lib/emojidex/service/indexes.rb +31 -10
- data/lib/emojidex/service/search.rb +5 -4
- data/lib/emojidex/service/transactor.rb +35 -19
- data/lib/emojidex/service/user.rb +80 -37
- data/lib/emojidex/service/user/history_item.rb +23 -0
- data/lib/emojidex/{data → util}/collection_checker.rb +2 -3
- metadata +10 -79
- data/.coveralls.yml +0 -1
- data/.gitignore +0 -12
- data/.rspec +0 -2
- data/.rubocop.yml +0 -18
- data/.travis.yml +0 -18
- data/Gemfile +0 -18
- data/Guardfile +0 -19
- data/README.md +0 -73
- data/spec/emojidex/data/categories_spec.rb +0 -19
- data/spec/emojidex/data/collection_checker_spec.rb +0 -72
- data/spec/emojidex/data/collection_spec.rb +0 -136
- data/spec/emojidex/data/emoji_spec.rb +0 -47
- data/spec/emojidex/data/extended_spec.rb +0 -118
- data/spec/emojidex/data/utf_spec.rb +0 -91
- data/spec/emojidex/service/collection_spec.rb +0 -20
- data/spec/emojidex/service/error_spec.rb +0 -17
- data/spec/emojidex/service/indexes_spec.rb +0 -62
- data/spec/emojidex/service/search_spec.rb +0 -87
- data/spec/emojidex/service/transactor_spec.rb +0 -11
- data/spec/emojidex/service/user_spec.rb +0 -128
- data/spec/spec_helper.rb +0 -18
- data/spec/support/Genshin.svg +0 -126
- data/spec/support/couple_kiss/0.svg +0 -177
- data/spec/support/couple_kiss/1.svg +0 -177
- data/spec/support/couple_kiss/10.svg +0 -293
- data/spec/support/couple_kiss/11.svg +0 -235
- data/spec/support/couple_kiss/12.svg +0 -235
- data/spec/support/couple_kiss/13.svg +0 -235
- data/spec/support/couple_kiss/14.svg +0 -177
- data/spec/support/couple_kiss/15.svg +0 -177
- data/spec/support/couple_kiss/2.svg +0 -177
- data/spec/support/couple_kiss/3.svg +0 -235
- data/spec/support/couple_kiss/4.svg +0 -235
- data/spec/support/couple_kiss/5.svg +0 -235
- data/spec/support/couple_kiss/6.svg +0 -293
- data/spec/support/couple_kiss/7.svg +0 -235
- data/spec/support/couple_kiss/8.svg +0 -235
- data/spec/support/couple_kiss/9.svg +0 -235
- data/spec/support/couple_kiss/animation.json +0 -14
- data/spec/support/fixtures/categories.json +0 -14
- data/spec/support/fixtures/category.json +0 -5
- data/spec/support/fixtures/emoji.json +0 -28
- data/spec/support/fixtures/emoji_detailed.json +0 -41
- data/spec/support/fixtures/search_emoji.json +0 -21
- data/spec/support/fixtures/single_emoji.json +0 -19
- data/spec/support/fixtures/single_emoji_detailed.json +0 -30
- data/spec/support/sample_collections/good/emoji.json +0 -30
- data/spec/support/sample_collections/good/mouth.svg +0 -49
- data/spec/support/sample_collections/good/nut_and_bolt.svg +0 -372
- data/spec/support/sample_collections/good/purple_heart.svg +0 -24
- data/spec/support/sample_collections/good/px32/mouth.png +0 -0
- data/spec/support/sample_collections/good/px32/nut_and_bolt.png +0 -0
- data/spec/support/sample_collections/good/px32/purple_heart.png +0 -0
- data/spec/support/sample_collections/good/px32/woman_with_bunny_ears.png +0 -0
- data/spec/support/sample_collections/good/woman_with_bunny_ears.svg +0 -90
- data/spec/support/sample_collections/missing_assets/emoji.json +0 -30
- data/spec/support/sample_collections/missing_assets/mouth.svg +0 -49
- data/spec/support/sample_collections/missing_assets/purple_heart.svg +0 -24
- data/spec/support/sample_collections/missing_assets/px32/mouth.png +0 -0
- data/spec/support/sample_collections/missing_assets/px32/nut_and_bolt.png +0 -0
- data/spec/support/sample_collections/missing_assets/px32/woman_with_bunny_ears.png +0 -0
- data/spec/support/sample_collections/missing_assets/woman_with_bunny_ears.svg +0 -90
- data/spec/support/sample_collections/missing_index/emoji.json +0 -23
- data/spec/support/sample_collections/missing_index/mouth.svg +0 -49
- data/spec/support/sample_collections/missing_index/nut_and_bolt.svg +0 -372
- data/spec/support/sample_collections/missing_index/purple_heart.svg +0 -24
- data/spec/support/sample_collections/missing_index/px32/mouth.png +0 -0
- data/spec/support/sample_collections/missing_index/px32/nut_and_bolt.png +0 -0
- data/spec/support/sample_collections/missing_index/px32/purple_heart.png +0 -0
- data/spec/support/sample_collections/missing_index/px32/woman_with_bunny_ears.png +0 -0
- data/spec/support/sample_collections/missing_index/woman_with_bunny_ears.svg +0 -90
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a23e3b7d0fdb86b4577cb31f2f4d507dd2aab718
|
|
4
|
+
data.tar.gz: c225211888f80285139ce2b5ab6722c7f56a3491
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0fde73983a81cbd08fb429a77a22c655329e16e4cbf8ff1d6bc43bdc8532ce39a85b8310df6d8a455d3845336728ded4147055b1e0059e044661e3b6a1bf117b
|
|
7
|
+
data.tar.gz: 56b050497be82e6917e5954dea7d269869f5b78b3f6912aebd127f9c22ed29ce89e5ecbb6d0d5bbac3e606867fa77a268c3e9fcf3c86c66c3b24548ddf214361
|
data/emojidex.gemspec
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
Gem::Specification.new do |s|
|
|
2
2
|
s.name = 'emojidex'
|
|
3
|
-
s.version = '0.
|
|
3
|
+
s.version = '0.2.0'
|
|
4
4
|
s.license = 'emojiOL'
|
|
5
5
|
s.summary = 'emojidex Ruby tools'
|
|
6
6
|
s.description = 'emojidex emoji handling, search and lookup, listing and caching functionality' \
|
|
7
7
|
' and user info (favorites/etc).'
|
|
8
8
|
s.authors = ['Rei Kagetsuki']
|
|
9
9
|
s.email = 'info@emojidex.com'
|
|
10
|
+
s.homepage = 'http://developer.emojidex.com'
|
|
10
11
|
|
|
11
12
|
s.required_ruby_version = '>= 2.0'
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
s.files = Dir.glob('emoji/**/*') +
|
|
14
|
+
Dir.glob('lib/**/*.rb') +
|
|
15
|
+
['emojidex.gemspec']
|
|
14
16
|
s.require_paths = ['lib']
|
|
15
|
-
s.homepage = 'http://developer.emojidex.com'
|
|
16
17
|
|
|
17
|
-
s.add_dependency 'faraday', '~> 0.9', '~> 0.9.
|
|
18
|
-
s.add_dependency 'faraday_middleware', '~> 0.9', '~> 0.9.
|
|
18
|
+
s.add_dependency 'faraday', '~> 0.9', '~> 0.9.2'
|
|
19
|
+
s.add_dependency 'faraday_middleware', '~> 0.9', '~> 0.9.2'
|
|
19
20
|
end
|
data/lib/emojidex.rb
CHANGED
|
@@ -7,6 +7,14 @@ require_relative 'emojidex/data/categories'
|
|
|
7
7
|
# Master emojidex module. Contains a few general helper functions.
|
|
8
8
|
module Emojidex
|
|
9
9
|
def self.escape_code(code)
|
|
10
|
-
code.tr(' ', '_')
|
|
10
|
+
code.tr(' ', '_').tr(':', '')
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.unescape_code(code)
|
|
14
|
+
code.tr('_', ' ')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.encapsulate_code(code)
|
|
18
|
+
"#{Emojidex::Defaults.encapsulator}#{unescape_code(code)}#{Emojidex::Defaults.encapsulator}"
|
|
11
19
|
end
|
|
12
20
|
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
require_relative 'defaults'
|
|
2
|
+
require_relative 'service/user'
|
|
3
|
+
require_relative 'data/collection'
|
|
4
|
+
|
|
5
|
+
module Emojidex
|
|
6
|
+
# A consolidated client which handles a user and their collection
|
|
7
|
+
class Client
|
|
8
|
+
@@client_cache_path = nil
|
|
9
|
+
@@user_instance = nil
|
|
10
|
+
@@collection_instance = nil
|
|
11
|
+
|
|
12
|
+
def self.USER
|
|
13
|
+
return @@user_instance unless @@user_instance.nil?
|
|
14
|
+
@@user_instance = Emojidex::Service::User.new
|
|
15
|
+
@@user_instance.load(@cache_path)
|
|
16
|
+
@@user_instance
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def user
|
|
20
|
+
Emojidex::Client.USER
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.COLLECTION
|
|
24
|
+
return @@collection_instance unless @@collection_instance.nil?
|
|
25
|
+
@@collection_instance = Emojidex::Data::Collection.new
|
|
26
|
+
@@collection_instance.load_cache
|
|
27
|
+
@@collection_instance
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def collection
|
|
31
|
+
Emojidex::Client.COLLECTION
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.CACHE_PATH
|
|
35
|
+
return @@client_cache_path unless @@client_cache_path.nil?
|
|
36
|
+
@@client_cache_path = Emojidex::Defaults.system_cache_path
|
|
37
|
+
@@client_cache_path
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def cache_path
|
|
41
|
+
Emojidex::Client.CACHE_PATH
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def initialize(opts = {})
|
|
45
|
+
if (opts.include? :cache_path)
|
|
46
|
+
@@client_cache_path = opts[:cache_path]
|
|
47
|
+
user = collection = nil
|
|
48
|
+
end
|
|
49
|
+
user
|
|
50
|
+
collection
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
module Emojidex
|
|
2
|
+
module Data
|
|
3
|
+
# Holds a master list of categories
|
|
4
|
+
class Categories
|
|
5
|
+
attr_accessor :categories
|
|
6
|
+
|
|
7
|
+
def initialize(categories_json = nil)
|
|
8
|
+
if categories_json
|
|
9
|
+
load_categories(categories_json)
|
|
10
|
+
else
|
|
11
|
+
load_standard_categories
|
|
12
|
+
end
|
|
13
13
|
end
|
|
14
|
-
end
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
# each override to map each functionality to the categories hash
|
|
16
|
+
def each(&block)
|
|
17
|
+
@categories.values.each(&block)
|
|
18
|
+
end
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
# select override to map select functionality to the categories hash
|
|
21
|
+
def select(&block)
|
|
22
|
+
@categories.values.select(&block)
|
|
23
|
+
end
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
# map override to map each functionality to the categories hash
|
|
26
|
+
def map(&block)
|
|
27
|
+
@categories.values.map(&block)
|
|
28
|
+
end
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
# collect override to map each functionality to the categories hash
|
|
31
|
+
def collect(&block)
|
|
32
|
+
@categories.values.collect(&block)
|
|
33
|
+
end
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
# loads categories from a JSON hash object / JSON text
|
|
36
|
+
def load_categories(json)
|
|
37
|
+
raw = JSON.parse(json, symbolize_names: true)
|
|
38
|
+
raw = raw[:categories]
|
|
40
39
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
@categories ||= {}
|
|
41
|
+
raw.each do |category_info|
|
|
42
|
+
category = Emojidex::Data::Category.new category_info
|
|
43
|
+
@categories[category.code.to_sym] = category
|
|
44
|
+
end
|
|
45
45
|
end
|
|
46
|
-
end
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
# loads standard categories local to the emojidex package
|
|
48
|
+
# *automatically called on initialize if no options are passed
|
|
49
|
+
def load_standard_categories
|
|
50
|
+
load_categories(IO.read(File.expand_path('../../../../emoji/categories.json', __FILE__)))
|
|
51
|
+
end
|
|
52
52
|
end
|
|
53
53
|
end
|
|
54
54
|
end
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
module Emojidex
|
|
2
|
+
module Data
|
|
3
|
+
# Category information
|
|
4
|
+
class Category
|
|
5
|
+
attr_accessor :code, :en, :ja
|
|
2
6
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def initialize(details = {})
|
|
9
|
-
@code = details[:code].to_sym
|
|
10
|
-
@en = details[:en]
|
|
11
|
-
@ja = details[:ja]
|
|
7
|
+
def initialize(details = {})
|
|
8
|
+
@code = details[:code].to_sym
|
|
9
|
+
@en = details[:en]
|
|
10
|
+
@ja = details[:ja]
|
|
11
|
+
end
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
14
|
end
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
|
|
3
3
|
require 'json'
|
|
4
|
+
require_relative '../../emojidex'
|
|
4
5
|
require_relative 'emoji'
|
|
5
6
|
require_relative 'categories'
|
|
6
7
|
require_relative 'collection/cache'
|
|
@@ -18,11 +19,17 @@ module Emojidex
|
|
|
18
19
|
:source_path, :vector_source_path, :raster_source_path
|
|
19
20
|
|
|
20
21
|
# Initialize Collection. You can pass a list of emoji to seed the collection
|
|
21
|
-
def initialize(
|
|
22
|
+
def initialize(opts = {})
|
|
22
23
|
@emoji = {}
|
|
23
24
|
@raster_source_path = @vector_source_path = @source_path = nil
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
if opts.include? :cache_path
|
|
26
|
+
setup_cache(opts[:cache_path])
|
|
27
|
+
opts.delete :cache_path
|
|
28
|
+
else
|
|
29
|
+
setup_cache
|
|
30
|
+
end
|
|
31
|
+
load_local_collection(opts[:local_load_path]) if opts.include? :local_load_path
|
|
32
|
+
add_emoji(opts[:emoji]) if opts.include? :emoji
|
|
26
33
|
@emoji
|
|
27
34
|
end
|
|
28
35
|
|
|
@@ -32,6 +39,7 @@ module Emojidex
|
|
|
32
39
|
json = IO.read(@source_path + '/emoji.json')
|
|
33
40
|
list = JSON.parse(json, symbolize_names: true)
|
|
34
41
|
add_emoji(list)
|
|
42
|
+
generate_paths
|
|
35
43
|
end
|
|
36
44
|
|
|
37
45
|
# each override to map each functionality to the emoji hash values
|
|
@@ -90,14 +98,14 @@ module Emojidex
|
|
|
90
98
|
end
|
|
91
99
|
|
|
92
100
|
def search(criteria = {})
|
|
93
|
-
Emojidex::Data::Collection.new _sub_search(@emoji.values.dup, criteria)
|
|
101
|
+
Emojidex::Data::Collection.new(emoji: _sub_search(@emoji.values.dup, criteria))
|
|
94
102
|
end
|
|
95
103
|
|
|
96
104
|
# Get all emoji from this collection that are part of the specified category
|
|
97
105
|
# Returns a new collection of only emoji in the specified category
|
|
98
106
|
def category(category_code)
|
|
99
107
|
categorized = @emoji.values.select { |moji| moji.category == category_code }
|
|
100
|
-
Emojidex::Data::Collection.new categorized
|
|
108
|
+
Emojidex::Data::Collection.new(emoji: categorized)
|
|
101
109
|
end
|
|
102
110
|
|
|
103
111
|
# Check to see if there are emoji in this collection which have the specified categories
|
|
@@ -109,14 +117,7 @@ module Emojidex
|
|
|
109
117
|
# Adds emojis to the collection
|
|
110
118
|
# After add categories are updated
|
|
111
119
|
def add_emoji(list)
|
|
112
|
-
list
|
|
113
|
-
if moji_info.instance_of? Emojidex::Data::Emoji
|
|
114
|
-
@emoji[moji_info.code.to_sym] = moji_info.dup
|
|
115
|
-
else
|
|
116
|
-
emoji = Emojidex::Data::Emoji.new moji_info
|
|
117
|
-
@emoji[emoji.code.to_sym] = emoji
|
|
118
|
-
end
|
|
119
|
-
end
|
|
120
|
+
_add_list(list)
|
|
120
121
|
categorize
|
|
121
122
|
associate_variants
|
|
122
123
|
condense_moji_code_data
|
|
@@ -125,23 +126,40 @@ module Emojidex
|
|
|
125
126
|
|
|
126
127
|
alias_method :<<, :add_emoji
|
|
127
128
|
|
|
129
|
+
def remove_emoji(code)
|
|
130
|
+
emoji.delete(code)
|
|
131
|
+
@emoji
|
|
132
|
+
end
|
|
133
|
+
|
|
128
134
|
private
|
|
129
135
|
|
|
136
|
+
def _add_list(list)
|
|
137
|
+
list.each do |moji_info|
|
|
138
|
+
if moji_info.instance_of? Emojidex::Data::Emoji
|
|
139
|
+
@emoji[moji_info.code.to_sym] = moji_info.dup
|
|
140
|
+
@emoji[moji_info.code.to_sym].paths = get_paths(moji_info)
|
|
141
|
+
else
|
|
142
|
+
emoji = Emojidex::Data::Emoji.new moji_info
|
|
143
|
+
emoji.paths = get_paths(emoji)
|
|
144
|
+
@emoji[Emojidex.escape_code(emoji.code.to_s).to_sym] = emoji
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
130
149
|
# Makes a list of all categories which contain emoji in this collection
|
|
131
150
|
def categorize
|
|
132
|
-
@categories = @emoji.values.map
|
|
151
|
+
@categories = @emoji.values.map(&:category)
|
|
133
152
|
@categories.uniq!
|
|
134
153
|
end
|
|
135
154
|
|
|
136
155
|
def associate_variants
|
|
137
156
|
@emoji.values.each do |emoji_obj|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
end
|
|
157
|
+
next unless emoji_obj.code.match(/\(.*\)$/) # this emoji is a variant
|
|
158
|
+
# check for base
|
|
159
|
+
base_code = emoji_obj.code.sub(/\(.*\)$/, '').to_sym
|
|
160
|
+
if @emoji.key? base_code
|
|
161
|
+
@emoji[base_code].variants << emoji_obj.code.to_sym
|
|
162
|
+
emoji_obj.base = base_code
|
|
145
163
|
end
|
|
146
164
|
end
|
|
147
165
|
end
|
|
@@ -5,13 +5,15 @@ module Emojidex
|
|
|
5
5
|
module Data
|
|
6
6
|
# Asset Information for Collections
|
|
7
7
|
module CollectionAssetInformation
|
|
8
|
-
def generate_checksums(formats = Emojidex::Defaults.formats,
|
|
8
|
+
def generate_checksums(formats = Emojidex::Defaults.formats,
|
|
9
|
+
sizes = Emojidex::Defaults.sizes)
|
|
9
10
|
@emoji.values.each do |moji|
|
|
10
11
|
moji.checksums = get_checksums(moji, formats, sizes)
|
|
11
12
|
end
|
|
12
13
|
end
|
|
13
14
|
|
|
14
|
-
def get_checksums(moji, formats = Emojidex::Defaults.formats,
|
|
15
|
+
def get_checksums(moji, formats = Emojidex::Defaults.formats,
|
|
16
|
+
sizes = Emojidex::Defaults.sizes)
|
|
15
17
|
sums = {}
|
|
16
18
|
sums[:svg] = _checksum_for_file("#{@cache_path}/#{moji.code}.svg") if formats.include? :svg
|
|
17
19
|
if formats.include? :png
|
|
@@ -29,7 +31,7 @@ module Emojidex
|
|
|
29
31
|
end
|
|
30
32
|
end
|
|
31
33
|
|
|
32
|
-
def get_paths(moji, formats = Emojidex::Defaults.formats, sizes = Emojidex::Defaults.sizes)
|
|
34
|
+
def get_paths?(moji, formats = Emojidex::Defaults.formats, sizes = Emojidex::Defaults.sizes)
|
|
33
35
|
paths = {}
|
|
34
36
|
path = "#{@cache_path}/#{moji.code}.svg"
|
|
35
37
|
paths[:svg] = path if File.exist? path
|
|
@@ -43,7 +45,21 @@ module Emojidex
|
|
|
43
45
|
paths
|
|
44
46
|
end
|
|
45
47
|
|
|
48
|
+
def get_paths(moji, formats = Emojidex::Defaults.formats,
|
|
49
|
+
sizes = Emojidex::Defaults.sizes)
|
|
50
|
+
paths = {}
|
|
51
|
+
paths[:svg] = "#{@cache_path}/#{moji.code}.svg"
|
|
52
|
+
if formats.include? :png
|
|
53
|
+
paths[:png] = {}
|
|
54
|
+
sizes.keys.each do |size|
|
|
55
|
+
paths[:png][size] = "#{@cache_path}/#{size}/#{moji.code}.png"
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
paths
|
|
59
|
+
end
|
|
60
|
+
|
|
46
61
|
private
|
|
62
|
+
|
|
47
63
|
def _checksum_for_file(path)
|
|
48
64
|
(File.exist? path) ? Digest::MD5.file(path).hexdigest : nil
|
|
49
65
|
end
|
|
@@ -18,15 +18,25 @@ module Emojidex
|
|
|
18
18
|
# check if cache dir is already set
|
|
19
19
|
return @cache_path if @cache_path && path.nil?
|
|
20
20
|
# setup cache
|
|
21
|
-
@cache_path =
|
|
21
|
+
@cache_path =
|
|
22
|
+
File.expand_path((path || Emojidex::Defaults.system_cache_path) + '/emoji')
|
|
22
23
|
# ENV['EMOJI_CACHE'] = @cache_path
|
|
23
24
|
FileUtils.mkdir_p(@cache_path)
|
|
24
25
|
Emojidex::Defaults.sizes.keys.each do |size|
|
|
25
26
|
FileUtils.mkdir_p(@cache_path + "/#{size}")
|
|
26
27
|
end
|
|
28
|
+
# load will expect emoji.json even if it contains no emoji
|
|
29
|
+
unless File.exist? "#{cache_path}/emoji.json"
|
|
30
|
+
File.open("#{@cache_path}/emoji.json", 'w') { |f| f.write '[]' }
|
|
31
|
+
end
|
|
27
32
|
@cache_path
|
|
28
33
|
end
|
|
29
34
|
|
|
35
|
+
def load_cache(path = nil)
|
|
36
|
+
setup_cache(path)
|
|
37
|
+
load_local_collection(@cache_path)
|
|
38
|
+
end
|
|
39
|
+
|
|
30
40
|
# Caches emoji to local emoji storage cache
|
|
31
41
|
# Options:
|
|
32
42
|
# cache_path: manually specify cache location
|
|
@@ -61,37 +71,42 @@ module Emojidex
|
|
|
61
71
|
def write_index(destination)
|
|
62
72
|
idx = @emoji.values.to_json
|
|
63
73
|
idx = JSON.parse idx
|
|
64
|
-
idx.each { |moji| moji.delete_if{ |
|
|
74
|
+
idx.each { |moji| moji.delete_if { |_k, v| v.nil? } }
|
|
65
75
|
File.open("#{destination}/emoji.json", 'w') { |f| f.write idx.to_json }
|
|
66
76
|
end
|
|
67
77
|
|
|
68
78
|
private
|
|
69
79
|
|
|
70
80
|
def _svg_check_copy(moji)
|
|
71
|
-
|
|
81
|
+
if @vector_source_path.nil? && @source_path.nil?
|
|
82
|
+
@download_queue << { moji: moji, formats: :svg, sizes: [] }
|
|
83
|
+
end
|
|
72
84
|
@vector_source_path = @source_path if @vector_source_path.nil?
|
|
73
85
|
src = "#{@vector_source_path}/#{moji.code}.svg"
|
|
74
86
|
if File.exist? "#{src}"
|
|
75
87
|
unless File.exist?("#{@cache_path}/#{moji.code}") &&
|
|
76
|
-
|
|
88
|
+
FileUtils.compare_file("#{src}", "#{@cache_path}/#{moji.code}.svg")
|
|
77
89
|
FileUtils.cp("#{src}", @cache_path)
|
|
78
90
|
end
|
|
79
91
|
else
|
|
80
|
-
|
|
92
|
+
@download_queue << { moji: moji, formats: :svg, sizes: [] }
|
|
81
93
|
end
|
|
82
94
|
FileUtils.cp_r src, @cache_path if File.directory? src
|
|
83
95
|
end
|
|
84
96
|
|
|
85
97
|
def _raster_check_copy(moji, format, sizes)
|
|
86
|
-
|
|
98
|
+
if @raster_source_path.nil? && @source_path.nil?
|
|
99
|
+
@download_queue << { moji: moji, formats: [format], sizes: sizes }
|
|
100
|
+
end
|
|
87
101
|
@raster_source_path = @source_path if @raster_source_path.nil?
|
|
88
|
-
|
|
102
|
+
moji.cache(format, sizes) if @raster_source_path.nil?
|
|
89
103
|
sizes.each do |size|
|
|
104
|
+
next if File.exist? "#{@cache_path}/#{size}/#{moji.code}.#{format}" # TODO: check checksums
|
|
90
105
|
src = "#{@raster_source_path}/#{size}/#{moji.code}"
|
|
91
106
|
if FileTest.exist? "#{src}.#{format}"
|
|
92
107
|
FileUtils.cp("#{src}.#{format}", ("#{@cache_path}/#{size}"))
|
|
93
|
-
else
|
|
94
|
-
|
|
108
|
+
else
|
|
109
|
+
@download_queue << { moji: moji, formats: [format], sizes: [size] }
|
|
95
110
|
end
|
|
96
111
|
FileUtils.cp_r(src, @cache_path) if File.directory? src
|
|
97
112
|
end
|
|
@@ -101,36 +116,16 @@ module Emojidex
|
|
|
101
116
|
thr = []
|
|
102
117
|
@download_queue.each do |dl|
|
|
103
118
|
thr << Thread.new { _cache_from_net(dl[:moji], dl[:formats], dl[:sizes]) }
|
|
104
|
-
thr.each
|
|
119
|
+
thr.each(&:join) if thr.length >= @download_threads
|
|
105
120
|
end
|
|
106
121
|
end
|
|
107
122
|
|
|
108
123
|
def _cache_from_net(moji, formats, sizes)
|
|
109
124
|
formats = *formats unless formats.class == Array
|
|
110
125
|
dls = []
|
|
111
|
-
dls << Thread.new {
|
|
112
|
-
dls << Thread.new {
|
|
113
|
-
dls.each
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
def _cache_svg_from_net(moji)
|
|
117
|
-
target = "#{@cache_path}/#{moji.code}.svg"
|
|
118
|
-
if File.exist? target # check for an existing copy so we don't double downlaod
|
|
119
|
-
return if moji.checksum?(:svg).nil? # no updates if we didn't get details
|
|
120
|
-
# if the checksums are the same there is no reason to update
|
|
121
|
-
return if moji.checksum?(:svg) == get_checksums(moji, [:svg])[:svg]
|
|
122
|
-
end
|
|
123
|
-
response = Emojidex::Service::Transactor.download("#{moji.code}.svg")
|
|
124
|
-
File.open(target, 'wb') { |fp|
|
|
125
|
-
fp.write(response.body) }
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
def _cache_raster_from_net(moji, format, sizes)
|
|
129
|
-
sizes.each do |size|
|
|
130
|
-
response = Emojidex::Service::Transactor.download("#{size}/#{moji.code}.#{format.to_s}")
|
|
131
|
-
File.open("#{@cache_path}/#{size}/#{moji.code}.#{format.to_s}", 'wb') { |fp|
|
|
132
|
-
fp.write(response.body) }
|
|
133
|
-
end
|
|
126
|
+
dls << Thread.new { moji.cache(:svg) } if formats.include? :svg
|
|
127
|
+
dls << Thread.new { moji.cache(:png, sizes) } if formats.include? :png
|
|
128
|
+
dls.each(&:join)
|
|
134
129
|
end
|
|
135
130
|
end
|
|
136
131
|
end
|