Class: Fontist::Import::Google::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/fontist/import/google/api.rb

Overview

Facade for accessing the unified Google Fonts database

This class provides a clean interface for accessing Google Fonts data by integrating data from three API endpoints (TTF, VF, WOFF2) into a unified database.

Examples:

Basic usage

fonts = Api.items
roboto = Api.font_by_name("Roboto")

Filtering

sans_serif = Api.by_category("sans-serif")
variable = Api.variable_fonts_only

Raw endpoint access

ttf_data = Api.ttf_data
vf_data = Api.vf_data

Class Method Summary collapse

Class Method Details

.by_category(category) ⇒ Array<Models::FontFamily>

Filter fonts by category

Parameters:

  • category (String)

    the category (e.g., “sans-serif”)

Returns:



56
57
58
# File 'lib/fontist/import/google/api.rb', line 56

def by_category(category)
  database.by_category(category)
end

.clear_cachevoid

This method returns an undefined value.

Clear all caches (clients + database)



105
106
107
108
109
110
# File 'lib/fontist/import/google/api.rb', line 105

def clear_cache
  ttf_client.clear_cache
  vf_client.clear_cache
  woff2_client.clear_cache
  @database = nil
end

.databaseFontDatabase

Get unified font database instance

Returns:



26
27
28
# File 'lib/fontist/import/google/api.rb', line 26

def database
  @database ||= build_database
end

.font_by_name(name) ⇒ Models::FontFamily?

Find a specific font family by name

Parameters:

  • name (String)

    the font family name

Returns:



48
49
50
# File 'lib/fontist/import/google/api.rb', line 48

def font_by_name(name)
  database.font_by_name(name)
end

.font_familiesArray<Models::FontFamily>

Alias for items

Returns:



40
41
42
# File 'lib/fontist/import/google/api.rb', line 40

def font_families
  items
end

.fonts_countHash

Get count of fonts by type

Returns:

  • (Hash)

    hash with counts of total, variable, and static



77
78
79
# File 'lib/fontist/import/google/api.rb', line 77

def fonts_count
  database.fonts_count
end

.itemsArray<Models::FontFamily>

Get all font families (main entry point)

Returns:



33
34
35
# File 'lib/fontist/import/google/api.rb', line 33

def items
  database.all_fonts
end

.static_fonts_onlyArray<Models::FontFamily>

Get only static fonts (fonts without axes)

Returns:



70
71
72
# File 'lib/fontist/import/google/api.rb', line 70

def static_fonts_only
  database.static_fonts_only
end

.ttf_dataArray<Models::FontFamily>

Get raw TTF endpoint data (for debugging)

Returns:



84
85
86
# File 'lib/fontist/import/google/api.rb', line 84

def ttf_data
  ttf_client.fetch
end

.variable_fonts_onlyArray<Models::FontFamily>

Get only variable fonts (fonts with axes)

Returns:



63
64
65
# File 'lib/fontist/import/google/api.rb', line 63

def variable_fonts_only
  database.variable_fonts_only
end

.vf_dataArray<Models::FontFamily>

Get raw VF endpoint data (for debugging)

Returns:



91
92
93
# File 'lib/fontist/import/google/api.rb', line 91

def vf_data
  vf_client.fetch
end

.woff2_dataArray<Models::FontFamily>

Get raw WOFF2 endpoint data (for debugging)

Returns:



98
99
100
# File 'lib/fontist/import/google/api.rb', line 98

def woff2_data
  woff2_client.fetch
end