Class: Hyde::FontFace

Inherits:
Object
  • Object
show all
Defined in:
lib/hyde_fonts/font_face.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(face) ⇒ FontFace

Returns a new instance of FontFace.



6
7
8
9
10
11
12
# File 'lib/hyde_fonts/font_face.rb', line 6

def initialize(face)
  @name = face["name"]
  @provider = face["provider"]
  @weights = face["weights"]
  @variants = parse_variants
  @css = []
end

Instance Attribute Details

#cssObject

Returns the value of attribute css.



4
5
6
# File 'lib/hyde_fonts/font_face.rb', line 4

def css
  @css
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/hyde_fonts/font_face.rb', line 3

def name
  @name
end

#providerObject (readonly)

Returns the value of attribute provider.



3
4
5
# File 'lib/hyde_fonts/font_face.rb', line 3

def provider
  @provider
end

Instance Method Details

#sort_variantsObject



14
15
16
17
18
# File 'lib/hyde_fonts/font_face.rb', line 14

def sort_variants
  @variants.sort do |a, b|
    (a.italic == b.italic) ? a.weight <=> b.weight : a.italic <=> b.italic
  end
end

#to_sObject



20
21
22
23
24
# File 'lib/hyde_fonts/font_face.rb', line 20

def to_s
  variants = sort_variants.map { |variant| variant.to_s }

  @name + ":ital,wght@" + variants.join(";")
end