Module: Ucode::Fetch::UcdZip

Defined in:
lib/ucode/fetch/ucd_zip.rb

Overview

Downloads UCD.zip from unicode.org and unpacks it into ‘Cache.ucd_dir(version)`.

Class Method Summary collapse

Class Method Details

.call(version, force: false) ⇒ Pathname

Returns the ucd_dir after extraction.

Parameters:

  • version (String)

    e.g. “17.0.0”

  • force (Boolean) (defaults to: false)

    re-download even if cached.

Returns:

  • (Pathname)

    the ucd_dir after extraction.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ucode/fetch/ucd_zip.rb', line 17

def call(version, force: false)
  Cache.ensure_version_dir!(version)
  target_dir = Cache.ucd_dir(version)

  marker = target_dir.join("UnicodeData.txt")
  return target_dir if marker.exist? && !force

  url = "#{Ucode.configuration.ucd_base_url}/#{version}#{URL_SUFFIX}"
  zip_path = Cache.version_dir(version).join("ucd.zip")
  Http.get(url, dest: zip_path)
  extract(zip_path, target_dir)
  zip_path.delete if zip_path.exist?
  target_dir
end