Class: Kotoshu::Cache::FrequencyCache
- Defined in:
- lib/kotoshu/cache/frequency_cache.rb
Overview
Frequency cache for Kelly Project frequency lists.
Manages Kelly frequency list downloads from the kotoshu/frequency-list-kelly repository. Resources are cached locally in ‘$XDG_CACHE_HOME/kotoshu/frequency-lists/code/` with metadata for versioning and expiration.
Extends BaseCache for common download, metadata, and validation logic.
Constant Summary collapse
- KELLY_LANGUAGES =
Kelly Project languages available
%w[ar zh en el it no ru sv].freeze
- GITHUB_REPO =
GitHub repository for Kelly frequency lists
"kotoshu/frequency-list-kelly"- GITHUB_BRANCH =
"main"
Instance Attribute Summary
Attributes inherited from BaseCache
#cache_path, #cache_ttl, #github_url, #source_registry, #url_base
Instance Method Summary collapse
-
#available_languages ⇒ Array<String>
Get list of available languages.
-
#cached_resources ⇒ Array<String>
List all cached resources.
-
#get_frequency(language_code, force_download: false) ⇒ Hash?
Get frequency data for a language (alias for get).
-
#supports_resource?(resource_id) ⇒ Boolean
Check if a resource type is supported.
Methods inherited from BaseCache
#available?, #clean, #clear, #clear_all, #download, #get, #initialize, #reset_stats, #stats
Constructor Details
This class inherits a constructor from Kotoshu::Cache::BaseCache
Instance Method Details
#available_languages ⇒ Array<String>
Get list of available languages.
37 38 39 |
# File 'lib/kotoshu/cache/frequency_cache.rb', line 37 def available_languages KELLY_LANGUAGES.dup end |
#cached_resources ⇒ Array<String>
List all cached resources.
61 62 63 64 65 66 |
# File 'lib/kotoshu/cache/frequency_cache.rb', line 61 def cached_resources directories = Dir.glob(File.join(@cache_path, "*")).select do |path| File.directory?(path) && !File.basename(path).start_with?(".") end directories.map { |path| File.basename(path) } end |
#get_frequency(language_code, force_download: false) ⇒ Hash?
Get frequency data for a language (alias for get).
46 47 48 |
# File 'lib/kotoshu/cache/frequency_cache.rb', line 46 def get_frequency(language_code, force_download: false) get(language_code, force_download) end |
#supports_resource?(resource_id) ⇒ Boolean
Check if a resource type is supported.
54 55 56 |
# File 'lib/kotoshu/cache/frequency_cache.rb', line 54 def supports_resource?(resource_id) KELLY_LANGUAGES.include?(resource_id) end |