Class: Ucode::Glyphs::PdfFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/ucode/glyphs/pdf_fetcher.rb

Overview

Resolves a Unicode block to its source PDF on disk.

Source: the per-block PDF cached at <cache>/<version>/pdfs/U<XXXX>.pdf (downloaded from unicode.org/charts/PDF/ by Ucode::Fetch::CodeCharts).

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ PdfFetcher

Returns a new instance of PdfFetcher.

Parameters:

  • version (String)

    UCD version, used as the cache namespace.



17
18
19
# File 'lib/ucode/glyphs/pdf_fetcher.rb', line 17

def initialize(version)
  @version = version
end

Instance Method Details

#fetch(block_first_cp:, force: false) ⇒ Pathname?

Resolve the per-block PDF for block_first_cp, fetching from the network if missing. Returns the local PDF path, or nil if the block's PDF is unavailable (network failure).

Parameters:

  • block_first_cp (Integer)

    first codepoint of the block; also the PDF's URL slug per unicode.org's naming convention.

  • force (Boolean) (defaults to: false)

    re-download even if cached.

Returns:

  • (Pathname, nil)


29
30
31
32
33
34
35
# File 'lib/ucode/glyphs/pdf_fetcher.rb', line 29

def fetch(block_first_cp:, force: false)
  path = per_block_path(block_first_cp)
  return path if path.exist? && !force

  download(block_first_cp)
  path if path.exist?
end