Module: Fontisan::Cldr::CacheManager

Defined in:
lib/fontisan/cldr/cache_manager.rb

Overview

Manages the on-disk CLDR cache layout.

Cache root resolution honors XDG_CONFIG_HOME per the XDG Base Directory Specification. Falls back to ~/.config on Unix.

Layout:

<root>/
<version>/
  json/                 # extracted CLDR JSON archive
    cldr-json/
      cldr-characters-full/
        main/<lang>/characters.json
  index/
    languages.yml       # built index of per-language codepoint sets

No network access — all methods are pure filesystem operations.

Class Method Summary collapse

Class Method Details

.cached?(version) ⇒ Boolean

True if the extracted JSON archive is present for this version.

Parameters:

  • version (String)

Returns:

  • (Boolean)


72
73
74
# File 'lib/fontisan/cldr/cache_manager.rb', line 72

def cached?(version)
  characters_main_dir(version).exist?
end

.cached_versionsArray<String>

All versions currently in the cache (sorted ascending).

Returns:

  • (Array<String>)


78
79
80
81
82
# File 'lib/fontisan/cldr/cache_manager.rb', line 78

def cached_versions
  return [] unless root.exist?

  root.children.select(&:directory?).map { |p| p.basename.to_s }.sort
end

.characters_main_dir(version) ⇒ Pathname

Directory containing the per-language characters.json files inside the extracted archive.

Parameters:

  • version (String)

Returns:

  • (Pathname)


54
55
56
# File 'lib/fontisan/cldr/cache_manager.rb', line 54

def characters_main_dir(version)
  json_dir(version).join("cldr-json", "cldr-characters-full", "main")
end

.ensure_version_dir!(version) ⇒ Object

Create the version directory and json/index subdirs. Idempotent.

Parameters:

  • version (String)


87
88
89
90
# File 'lib/fontisan/cldr/cache_manager.rb', line 87

def ensure_version_dir!(version)
  json_dir(version).mkpath
  index_dir(version).mkpath
end

.index_dir(version) ⇒ Pathname

Directory holding the derived language index for a version.

Parameters:

  • version (String)

Returns:

  • (Pathname)


61
62
63
# File 'lib/fontisan/cldr/cache_manager.rb', line 61

def index_dir(version)
  version_dir(version).join("index")
end

.json_dir(version) ⇒ Pathname

Directory where the raw CLDR JSON archive is extracted.

Parameters:

  • version (String)

Returns:

  • (Pathname)


46
47
48
# File 'lib/fontisan/cldr/cache_manager.rb', line 46

def json_dir(version)
  version_dir(version).join("json")
end

.languages_index_path(version) ⇒ Object



65
66
67
# File 'lib/fontisan/cldr/cache_manager.rb', line 65

def languages_index_path(version)
  index_dir(version).join(LANGUAGES_INDEX_FILENAME)
end

.remove_version(version) ⇒ Object

Remove a version from the cache. No-op if absent.

Parameters:

  • version (String)


94
95
96
97
# File 'lib/fontisan/cldr/cache_manager.rb', line 94

def remove_version(version)
  dir = version_dir(version)
  dir.rmtree if dir.exist?
end

.rootPathname

Root path of the CLDR cache.

Returns:

  • (Pathname)


31
32
33
34
# File 'lib/fontisan/cldr/cache_manager.rb', line 31

def root
  base = xdg_config_home || File.join(Dir.home, ".config")
  Pathname.new(base).join("fontisan", "cldr")
end

.version_dir(version) ⇒ Pathname

Per-version directory.

Parameters:

  • version (String)

    e.g. "46.0.0"

Returns:

  • (Pathname)


39
40
41
# File 'lib/fontisan/cldr/cache_manager.rb', line 39

def version_dir(version)
  root.join(version)
end