Class: Fontist::Import::Google::Models::FontVariant

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/fontist/import/google/models/font_variant.rb

Constant Summary collapse

VALID_FORMATS =

Valid font formats

%i[ttf woff2].freeze

Instance Method Summary collapse

Instance Method Details

#descriptionString

Get a human-readable description of the variant

Returns:

  • (String)

    description of the variant



64
65
66
# File 'lib/fontist/import/google/models/font_variant.rb', line 64

def description
  "#{name} (#{format})"
end

#extensionString

Get the file extension for this variant

Returns:

  • (String)

    the file extension (.ttf or .woff2)



36
37
38
39
40
41
42
43
44
45
# File 'lib/fontist/import/google/models/font_variant.rb', line 36

def extension
  case format.to_sym
  when :ttf
    ".ttf"
  when :woff2
    ".woff2"
  else
    ""
  end
end

#ttf?Boolean

Check if format is TTF

Returns:

  • (Boolean)

    true if format is :ttf



50
51
52
# File 'lib/fontist/import/google/models/font_variant.rb', line 50

def ttf?
  format.to_sym == :ttf
end

#valid_format?Boolean

Validate the format

Returns:

  • (Boolean)

    true if format is valid



71
72
73
# File 'lib/fontist/import/google/models/font_variant.rb', line 71

def valid_format?
  VALID_FORMATS.include?(format.to_sym)
end

#variable_font?(family = nil) ⇒ Boolean

Check if this is a variable font Note: This requires access to the parent family’s axes Should be called with the parent family as context

Parameters:

  • family (FontFamily) (defaults to: nil)

    the parent font family

Returns:

  • (Boolean)

    true if the parent family has axes



27
28
29
30
31
# File 'lib/fontist/import/google/models/font_variant.rb', line 27

def variable_font?(family = nil)
  return false if family.nil?

  family.variable_font?
end

#woff2?Boolean

Check if format is WOFF2

Returns:

  • (Boolean)

    true if format is :woff2



57
58
59
# File 'lib/fontist/import/google/models/font_variant.rb', line 57

def woff2?
  format.to_sym == :woff2
end