Class: WebFont::Finder
- Inherits:
-
Object
- Object
- WebFont::Finder
- Defined in:
- lib/web_font/finder.rb
Instance Attribute Summary collapse
-
#indices ⇒ Object
readonly
Returns the value of attribute indices.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
Instance Method Summary collapse
-
#find(font_family) ⇒ Object
Find font in the index.
-
#info(font_family) ⇒ Object
A convenient method to get all font variants.
-
#initialize ⇒ Finder
constructor
A new instance of Finder.
Constructor Details
#initialize ⇒ Finder
6 7 8 9 |
# File 'lib/web_font/finder.rb', line 6 def initialize @indices = read_indices @items = read_fonts['items'] end |
Instance Attribute Details
#indices ⇒ Object (readonly)
Returns the value of attribute indices.
4 5 6 |
# File 'lib/web_font/finder.rb', line 4 def indices @indices end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
4 5 6 |
# File 'lib/web_font/finder.rb', line 4 def items @items end |
Instance Method Details
#find(font_family) ⇒ Object
Find font in the index
Returns hash
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/web_font/finder.rb', line 14 def find(font_family) font_family = font_family.downcase alphabet = font_family[0] hash = indices[alphabet] return {} unless hash start = hash['start'] item = while start <= hash['end'] break items[start] if match?(font_family, items[start]['family']) start += 1 end item || {} end |
#info(font_family) ⇒ Object
A convenient method to get all font variants
Returns array
33 34 35 36 37 38 39 40 41 |
# File 'lib/web_font/finder.rb', line 33 def info(font_family) item = find(font_family) return [] unless item['family'] font_family = item['family'].gsub(/\s/, '-') item['files'].map do |variant, url| "#{font_family}-#{variant}#{File.extname(url)}" end end |