Class: Fontist::Import::Google::DataSources::Github

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

Overview

Data source for fetching font data from Google Fonts GitHub repository

This data source reads font metadata from a local clone of the Google Fonts repository, parsing METADATA.pb files and extracting information from font files using otfinfo.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_path:) ⇒ Github

Initialize a new GitHub data source

Parameters:

  • source_path (String)

    Path to Google Fonts repository



19
20
21
22
23
# File 'lib/fontist/import/google/data_sources/github.rb', line 19

def initialize(source_path:)
  @source_path = Pathname.new(source_path)
  @cache = nil
  validate_source_path!
end

Instance Attribute Details

#source_pathObject (readonly)

Returns the value of attribute source_path.



14
15
16
# File 'lib/fontist/import/google/data_sources/github.rb', line 14

def source_path
  @source_path
end

Instance Method Details

#clear_cachenil

Clear the internal cache

Returns:

  • (nil)


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

def clear_cache
  @cache = nil
end

#fetchArray<FontFamily>

Fetch and parse all font families from the repository

Returns:

  • (Array<FontFamily>)

    array of parsed font family models



28
29
30
31
32
# File 'lib/fontist/import/google/data_sources/github.rb', line 28

def fetch
  return @cache if @cache

  @cache = parse_all_fonts
end

#fetch_family(name) ⇒ FontFamily?

Fetch a specific font family by name

Parameters:

  • name (String)

    the font family name

Returns:

  • (FontFamily, nil)

    the font family if found



38
39
40
41
42
43
# File 'lib/fontist/import/google/data_sources/github.rb', line 38

def fetch_family(name)
  family_path = find_family_path(name)
  return nil unless family_path

  parse_family(family_path)
end