Class: Foxtail::ICU4XCache
- Inherits:
-
Object
- Object
- Foxtail::ICU4XCache
- Extended by:
- Dry::Core::Cache
- Includes:
- Singleton
- Defined in:
- lib/foxtail/icu4x_cache.rb
Overview
Singleton cache for ICU4X formatter and rules instances.
ICU4X formatters and rules internally load and parse locale data, making instance creation non-trivial. This cache stores instances keyed by locale and options to avoid repeated instantiation.
Thread safety is provided by Dry::Core::Cache, which uses Concurrent::Map internally.
Instance Method Summary collapse
-
#datetime_formatter(locale, **options) ⇒ ICU4X::DateTimeFormat
Returns a cached ICU4X::DateTimeFormat instance.
-
#number_formatter(locale, **options) ⇒ ICU4X::NumberFormat
Returns a cached ICU4X::NumberFormat instance.
-
#plural_rules(locale, type: :cardinal) ⇒ ICU4X::PluralRules
Returns a cached ICU4X::PluralRules instance.
Instance Method Details
#datetime_formatter(locale, **options) ⇒ ICU4X::DateTimeFormat
Returns a cached ICU4X::DateTimeFormat instance.
40 41 42 43 44 |
# File 'lib/foxtail/icu4x_cache.rb', line 40 def datetime_formatter(locale, **) self.class.fetch_or_store(:datetime_formatter, locale, ) do ICU4X::DateTimeFormat.new(locale, **) end end |
#number_formatter(locale, **options) ⇒ ICU4X::NumberFormat
Returns a cached ICU4X::NumberFormat instance.
29 30 31 32 33 |
# File 'lib/foxtail/icu4x_cache.rb', line 29 def number_formatter(locale, **) self.class.fetch_or_store(:number_formatter, locale, ) do ICU4X::NumberFormat.new(locale, **) end end |
#plural_rules(locale, type: :cardinal) ⇒ ICU4X::PluralRules
Returns a cached ICU4X::PluralRules instance.
51 52 53 54 55 |
# File 'lib/foxtail/icu4x_cache.rb', line 51 def plural_rules(locale, type: :cardinal) self.class.fetch_or_store(:plural_rules, locale, type) do ICU4X::PluralRules.new(locale, type:) end end |