lib/web_font/data.rb in web_font-0.0.5 vs lib/web_font/data.rb in web_font-0.0.6
- old
+ new
@@ -6,33 +6,55 @@
class << self
attr_accessor :path
end
- # Download fonts data from Google and index it
+ # Download font index from Google, save it locally and index it.
#
+ # fonts.json schema:
+ # {
+ # "kind": "webfonts#webfontList",
+ # "items": [
+ # {
+ # "kind": "webfonts#webfont",
+ # "family": "ABeeZee",
+ # "variants": [
+ # "regular",
+ # "italic"
+ # ],
+ # "subsets": [
+ # "latin"
+ # ],
+ # "version": "v1",
+ # "lastModified": "2013-12-16",
+ # "files": {
+ # "regular": "http://themes.googleusercontent.com/static/fonts/abeezee/v1/mE5BOuZKGln_Ex0uYKpIaw.ttf",
+ # "italic": "http://themes.googleusercontent.com/static/fonts/abeezee/v1/kpplLynmYgP0YtlJA3atRw.ttf"
+ # }
+ # },
+ # { ... },
+ # { ... }
+ # ]
+ # }
+ #
# Returns nothing
def self.download
- assert_path!
+ raise ArgumentError, 'path is empty' unless path
raise ArgumentError, "ENV['GOOGLE_API_KEY'] is nil" unless ENV['GOOGLE_API_KEY']
FileUtils.mkdir_p(path) unless Dir.exist?(path)
url = "https://www.googleapis.com/webfonts/v1/webfonts?key=#{ENV['GOOGLE_API_KEY']}"
- system("wget -O #{path}/fonts.json #{url}")
+ system("wget -q -O #{path}/fonts.json #{url}")
index
end
- def self.assert_path!
- raise ArgumentError, 'path is empty' unless path
- end
-
private
- # Index fonts data so it will speed things up when search
- #
- # Returns nothing
+ # Index font data so it will speed things up when searching
+ #
+ # Returns nothing
def self.index
indices = {}
alphabet = 'a'
indices[alphabet] = { 'start' => 0 }