web_font 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e74d4f14d58ae8a0ecac95f391c507f853eb2db7
4
- data.tar.gz: 3e514ba3186ed4d242fb9505b35a848cec4772c0
3
+ metadata.gz: 1797db0f5be3a95b6051fa734a0792eb31008d2a
4
+ data.tar.gz: 8335727402909e97cd97e99473fdb68a97e3cee4
5
5
  SHA512:
6
- metadata.gz: 5eea539b1a743827b57dd7bee062bf2f144cc629ee88505344bce59f7d56ef03e026d5360cdca8acd60daa622f994b319b9ab000180d7f6b3c1e73695f9fc43b
7
- data.tar.gz: f15d7dabc2a0ff20d5734e5b76509b8b01f48d01c8b30ddd5ef4205592236c2f314a97f3bb9657add38af861c66f25b27822ae0e1e119bb41542dcae786b6904
6
+ metadata.gz: 67a78d99efcd2aee784a49c04394affd67cf59cccd3fa8224398639a7e400be1d26876f42073cc8944b32df85215cfc4744274134adeed314960cf718478cccd
7
+ data.tar.gz: 756237552de9293071d2fe19b3b5c0ed03d83b22a0616bee67bb47206e6e160b2d8078f8aa4aa2af8682544c5d0ad41306efd85eaafe93978bc7d354be7f013a
data/lib/web_font/data.rb CHANGED
@@ -11,16 +11,20 @@ module WebFont
11
11
  # Download fonts data from Google and index it
12
12
  #
13
13
  # Returns nothing
14
- def self.download(destination = nil)
14
+ def self.download
15
+ assert_path!
15
16
  raise ArgumentError, "ENV['GOOGLE_API_KEY'] is nil" unless ENV['GOOGLE_API_KEY']
16
17
 
17
- destination ||= path
18
- FileUtils.mkdir_p(destination) unless Dir.exist?(destination)
18
+ FileUtils.mkdir_p(path) unless Dir.exist?(path)
19
19
 
20
20
  url = "https://www.googleapis.com/webfonts/v1/webfonts?key=#{ENV['GOOGLE_API_KEY']}"
21
- system("wget -O #{destination}/fonts.json #{url}")
21
+ system("wget -O #{path}/fonts.json #{url}")
22
22
 
23
- index(destination)
23
+ index
24
+ end
25
+
26
+ def self.assert_path!
27
+ raise ArgumentError, 'path is empty' unless path
24
28
  end
25
29
 
26
30
  private
@@ -28,12 +32,12 @@ module WebFont
28
32
  # Index fonts data so it will speed things up when search
29
33
  #
30
34
  # Returns nothing
31
- def self.index(destination)
35
+ def self.index
32
36
  indices = {}
33
37
  alphabet = 'a'
34
38
  indices[alphabet] = { 'start' => 0 }
35
39
 
36
- hash = JSON.parse(File.open("#{destination}/fonts.json").read)
40
+ hash = JSON.parse(File.open("#{path}/fonts.json").read)
37
41
  hash['items'].each_with_index do |item, index|
38
42
  family = item['family']
39
43
 
@@ -46,7 +50,7 @@ module WebFont
46
50
  end
47
51
  indices[alphabet]['end'] = hash['items'].size - 1
48
52
 
49
- File.open("#{destination}/index.json", 'w') { |file| file.write(indices.to_json) }
53
+ File.open("#{path}/index.json", 'w') { |file| file.write(indices.to_json) }
50
54
  end
51
55
  end
52
56
  end
@@ -1,3 +1,3 @@
1
1
  module WebFont
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end