emojidex 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e6f88686eccedc6de0ac1cc7fae3d7cbe5ecea2
4
- data.tar.gz: 7c50835110dd0241205e3793b2a557cc1b31fce8
3
+ metadata.gz: 4ea575d94d7d398288be6ce736bc20e366267943
4
+ data.tar.gz: e049cb63c893faef50480ece90d00ab4c9372195
5
5
  SHA512:
6
- metadata.gz: 1f0bc60a900cdf724fc878d5b4c7cb0f13921c105c017a61ce9443ed920dc412717af1fd10a86f0b3ce513ac6192e209f93293e4dbc1670391e654a103e2107f
7
- data.tar.gz: 088cdba0c8bed81cebee332c1bec647dbf41c797c4b7d9466a5a6d0dc764ae67c751752cc5b80f94c7ab34eaf85af60543f65d08e95833b4dff0d929889c7807
6
+ metadata.gz: 373cbf2c210c2b3f778c83e00b6d1b8196f4fd7c37fa857abca99e304d21c30657ccec4853b75824cc9a75769dbd43a0d252cbd8ef0523c42be670927da74945
7
+ data.tar.gz: a5bd556fd516939f75ed1531ad7c88d4fdcaa41c61ee102790d204f22d7af6b6887fddf5a94646307930b0430025eee45e4efd5d2e6c5161b7f9f9db4cac5028
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'emojidex'
3
- s.version = '0.2.2'
3
+ s.version = '0.2.3'
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' \
@@ -9,12 +9,12 @@ Gem::Specification.new do |s|
9
9
  s.email = 'info@emojidex.com'
10
10
  s.homepage = 'http://developer.emojidex.com'
11
11
 
12
- s.required_ruby_version = '>= 2.0'
12
+ s.required_ruby_version = '>= 2.2'
13
13
  s.files = Dir.glob('emoji/**/*') +
14
14
  Dir.glob('lib/**/*.rb') +
15
15
  ['emojidex.gemspec']
16
16
  s.require_paths = ['lib']
17
17
 
18
18
  s.add_dependency 'faraday', '~> 0.9', '~> 0.9.2'
19
- s.add_dependency 'faraday_middleware', '~> 0.9', '~> 0.9.2'
19
+ s.add_dependency 'faraday_middleware', '~> 0.10', '~> 0.10.0'
20
20
  end
@@ -37,13 +37,17 @@ module Emojidex
37
37
 
38
38
  # Loads an emoji collection on local storage
39
39
  def load_local_collection(path)
40
- @source_path = File.expand_path(path)
40
+ @source_path = @vector_source_path = @raster_source_path = File.expand_path(path)
41
41
  json = IO.read(@source_path + '/emoji.json')
42
42
  list = JSON.parse(json, symbolize_names: true)
43
43
  add_emoji(list)
44
44
  generate_paths
45
45
  end
46
46
 
47
+ def emojis
48
+ @emoji.values
49
+ end
50
+
47
51
  # each override to map each functionality to the emoji hash values
48
52
  def each(&block)
49
53
  @emoji.values.each(&block)
@@ -15,11 +15,11 @@ module Emojidex
15
15
  def get_checksums(moji, formats = Emojidex::Defaults.formats,
16
16
  sizes = Emojidex::Defaults.sizes)
17
17
  sums = {}
18
- sums[:svg] = _checksum_for_file("#{@cache_path}/#{moji.code}.svg") if formats.include? :svg
18
+ sums[:svg] = _checksum_for_file("#{@vector_source_path}/#{moji.code}.svg") if formats.include? :svg
19
19
  if formats.include? :png
20
20
  sums[:png] = {}
21
21
  sizes.keys.each do |size|
22
- sums[:png][size] = _checksum_for_file("#{@cache_path}/#{size}/#{moji.code}.png")
22
+ sums[:png][size] = _checksum_for_file("#{@raster_source_path}/#{size}/#{moji.code}.png")
23
23
  end
24
24
  end
25
25
  sums
@@ -33,12 +33,12 @@ module Emojidex
33
33
 
34
34
  def get_paths?(moji, formats = Emojidex::Defaults.formats, sizes = Emojidex::Defaults.sizes)
35
35
  paths = {}
36
- path = "#{@cache_path}/#{moji.code}.svg"
36
+ path = "#{@vector_source_path}/#{moji.code}.svg"
37
37
  paths[:svg] = path if File.exist? path
38
38
  if formats.include? :png
39
39
  paths[:png] = {}
40
40
  sizes.keys.each do |size|
41
- path = "#{@cache_path}/#{size}/#{moji.code}.png"
41
+ path = "#{@raster_source_path}/#{size}/#{moji.code}.png"
42
42
  paths[:png][size] = path if File.exist? path
43
43
  end
44
44
  end
@@ -48,11 +48,11 @@ module Emojidex
48
48
  def get_paths(moji, formats = Emojidex::Defaults.formats,
49
49
  sizes = Emojidex::Defaults.sizes)
50
50
  paths = {}
51
- paths[:svg] = "#{@cache_path}/#{moji.code}.svg"
51
+ paths[:svg] = "#{@vector_source_path}/#{moji.code}.svg"
52
52
  if formats.include? :png
53
53
  paths[:png] = {}
54
54
  sizes.keys.each do |size|
55
- paths[:png][size] = "#{@cache_path}/#{size}/#{moji.code}.png"
55
+ paths[:png][size] = "#{@raster_source_path}/#{size}/#{moji.code}.png"
56
56
  end
57
57
  end
58
58
  paths
@@ -61,7 +61,11 @@ module Emojidex
61
61
  private
62
62
 
63
63
  def _checksum_for_file(path)
64
- (File.exist? path) ? Digest::MD5.file(path).hexdigest : nil
64
+ sum = nil
65
+ if File.exist? path
66
+ sum = Digest::MD5.file(path).hexdigest
67
+ end
68
+ sum
65
69
  end
66
70
  end
67
71
  end
@@ -40,7 +40,6 @@ module Emojidex
40
40
  # Caches emoji to local emoji storage cache
41
41
  # Options:
42
42
  # cache_path: manually specify cache location
43
- # (default is ENV['EMOJI_CACHE'] or '$HOME/.emoji_cache')
44
43
  # formats: formats to cache (default is SVG only)
45
44
  # sizes: sizes to cache (default is px32, but this is irrelivant for SVG)
46
45
  def cache(options = {})
@@ -52,7 +51,6 @@ module Emojidex
52
51
  # +regenerates checksums and paths
53
52
  # Options:
54
53
  # cache_path: manually specify cache location
55
- # (default is ENV['EMOJI_CACHE'] or '$HOME/.emoji_cache')
56
54
  # formats: formats to cache (default is SVG only)
57
55
  # sizes: sizes to cache (default is px32, but this is irrelivant for SVG)
58
56
  def cache!(options = {})
@@ -90,37 +88,24 @@ module Emojidex
90
88
  private
91
89
 
92
90
  def _svg_check_copy(moji)
93
- if @vector_source_path.nil? && @source_path.nil?
94
- @download_queue << { moji: moji, formats: :svg, sizes: [] }
95
- end
96
- @vector_source_path = @source_path if @vector_source_path.nil?
97
91
  src = "#{@vector_source_path}/#{moji.code}.svg"
98
92
  if File.exist? "#{src}"
99
- unless File.exist?("#{@cache_path}/#{moji.code}.svg") &&
100
- FileUtils.compare_file("#{src}", "#{@cache_path}/#{moji.code}.svg")
101
- FileUtils.cp("#{src}", @cache_path)
102
- end
93
+ FileUtils.cp("#{src}", @cache_path) unless @vector_source_path == @cache_path
103
94
  else
104
95
  @download_queue << { moji: moji, formats: :svg, sizes: [] }
105
96
  end
106
- FileUtils.cp_r src, @cache_path if File.directory? src
97
+ FileUtils.cp_r src, @cache_path if File.directory? src # Copies source frames and data files if unpacked
107
98
  end
108
99
 
109
100
  def _raster_check_copy(moji, format, sizes)
110
- if @raster_source_path.nil? && @source_path.nil?
111
- @download_queue << { moji: moji, formats: [format], sizes: sizes }
112
- end
113
- @raster_source_path = @source_path if @raster_source_path.nil?
114
- moji.cache(format, sizes) if @raster_source_path.nil?
115
101
  sizes.each do |size|
116
- next if File.exist? "#{@cache_path}/#{size}/#{moji.code}.#{format}" # TODO: check checksums
117
102
  src = "#{@raster_source_path}/#{size}/#{moji.code}"
118
- if FileTest.exist? "#{src}.#{format}"
119
- FileUtils.cp("#{src}.#{format}", ("#{@cache_path}/#{size}"))
103
+ if File.exist? "#{src}.#{format}"
104
+ FileUtils.cp("#{src}.#{format}", ("#{@cache_path}/#{size}")) unless @raster_source_path == @cache_path
120
105
  else
121
106
  @download_queue << { moji: moji, formats: [format], sizes: [size] }
122
107
  end
123
- FileUtils.cp_r(src, @cache_path) if File.directory? src
108
+ FileUtils.cp_r(src, @cache_path) if File.directory? src # Copies source frames and data files if unpacked
124
109
  end
125
110
  end
126
111
 
@@ -130,6 +115,7 @@ module Emojidex
130
115
  thr << Thread.new { _cache_from_net(dl[:moji], dl[:formats], dl[:sizes]) }
131
116
  thr.each(&:join) if thr.length >= @download_threads
132
117
  end
118
+ thr.each(&:join) # grab end of queue
133
119
  end
134
120
 
135
121
  def _cache_from_net(moji, formats, sizes)
@@ -144,11 +130,18 @@ module Emojidex
144
130
  setup_cache options[:cache_path]
145
131
  formats = options[:formats] || Emojidex::Defaults.selected_formats
146
132
  sizes = options[:sizes] || Emojidex::Defaults.selected_sizes
133
+
134
+ @vector_source_path = @cache_path if @vector_source_path.nil?
135
+ @raster_source_path = @cache_path if @raster_source_path.nil?
136
+
147
137
  @emoji.values.each do |moji|
148
138
  _svg_check_copy(moji) if formats.include? :svg
149
139
  _raster_check_copy(moji, :png, sizes) if formats.include? :png
150
140
  end
151
141
  _process_download_queue
142
+
143
+ @vector_source_path = @cache_path if formats.include? :svg
144
+ @raster_source_path = @cache_path if formats.include? :png
152
145
  end
153
146
  end
154
147
  end
@@ -115,7 +115,10 @@ module Emojidex
115
115
  end
116
116
 
117
117
  def _cache_png(sizes)
118
+ sizes = sizes.keys if sizes.is_a?(Hash)
118
119
  sizes.each do |size|
120
+ size = size.first if size.is_a?(Array)
121
+ size = size.key if size.is_a?(Hash)
119
122
  unless @paths.include?(:png) &&
120
123
  @paths[:png].include?(size) && @paths[:png][size].nil? == false
121
124
  @paths[:png][size] = "#{Dir.pwd}/#{size}/#{@code}.png"
@@ -100,6 +100,8 @@ module Emojidex
100
100
  else
101
101
  setup_cache
102
102
  end
103
+
104
+ @raster_source_path = @vector_source_path = @source_path = @cache_path
103
105
  end
104
106
  end
105
107
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emojidex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rei Kagetsuki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-31 00:00:00.000000000 Z
11
+ date: 2016-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -36,20 +36,20 @@ dependencies:
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '0.9'
39
+ version: '0.10'
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
- version: 0.9.2
42
+ version: 0.10.0
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - "~>"
48
48
  - !ruby/object:Gem::Version
49
- version: '0.9'
49
+ version: '0.10'
50
50
  - - "~>"
51
51
  - !ruby/object:Gem::Version
52
- version: 0.9.2
52
+ version: 0.10.0
53
53
  description: emojidex emoji handling, search and lookup, listing and caching functionality
54
54
  and user info (favorites/etc).
55
55
  email: info@emojidex.com
@@ -94,7 +94,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - ">="
96
96
  - !ruby/object:Gem::Version
97
- version: '2.0'
97
+ version: '2.2'
98
98
  required_rubygems_version: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - ">="