Module: GoogleFontExtractor
- Defined in:
- lib/extract.rb,
lib/version.rb,
lib/google_font_extractor.rb
Defined Under Namespace
Modules: Extract
Constant Summary collapse
- VERSION =
'0.0.2'
- CATEGORIES =
%w(serif sans-serif display handwriting)
Class Method Summary collapse
Class Method Details
.fonts ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/google_font_extractor.rb', line 11 def self.fonts # main list final_font_list = [] CATEGORIES.each do |category| # Get intermediate list of fonts font_list = Extract::FontList.scrape(URI.parse("http://www.google.com/webfonts?sort=pop&category=#{category}")) # Build final list of real fonts. Some fonts are listed are grouped by family on the main font # list, break those familiies down into individual fonts. font_list.each_with_index do |font, idx| if font.families_count then Extract::FontList.scrape(URI.parse("http://www.google.com/webfonts/list?family=#{URI.encode(font.name)}&sort=pop&category=#{category}")).each do |intermediate| intermediate[:category] = category final_font_list << intermediate end else font[:category] = category final_font_list << font end end end # Tidy. final_font_list.flatten! # Further enhance final list of fonts with additional information from the individual font pages # so we can provide information about the font weights (bold, etc) that are available. final_font_list.each_with_index do |font, idx| font_page = Extract::FontPage.scrape(URI.parse("http://www.google.com/webfonts/family?family=#{URI.encode(font.name)}")) font[:weights] = font_page.weights font[:download_url] = font_page.download_url end end |