Module: Timeprice::Supported
- Defined in:
- lib/timeprice/supported.rb
Overview
Supported country and currency codes, derived from ‘data/manifest.json`. Adding a country = drop a CPI file + regenerate the manifest. No code change required.
Everything that needs to know “which currency pairs with which CPI series” must read it from here.
Constant Summary collapse
- ZERO_DECIMAL_CURRENCIES =
Currencies with no minor unit — formatted as whole numbers. This is ISO 4217 metadata, not bundled data, so it stays hardcoded.
%w[JPY KRW VND].freeze
Class Method Summary collapse
-
.annual_only_currencies ⇒ Array<String>
Currencies served only annually (e.g. VND, RUB).
-
.countries ⇒ Array<String>
Frozen list of supported country codes.
- .country?(country) ⇒ Boolean
-
.country_for_currency(currency) ⇒ String?
Country code, or nil if unsupported.
-
.country_to_currency ⇒ Hash{String=>String}
Country code → currency code.
-
.currencies ⇒ Array<String>
Frozen list of supported currency codes (the FX base USD plus every currency the manifest declares).
- .currency?(currency) ⇒ Boolean
-
.currency_for_country(country) ⇒ String?
Currency code, or nil if unsupported.
-
.currency_to_country ⇒ Hash{String=>String}
Currency code → country code.
-
.daily_currencies ⇒ Array<String>
Currencies with daily FX observations.
-
.decimals_for(currency) ⇒ Integer
ISO 4217 minor-unit count for a currency.
Class Method Details
.annual_only_currencies ⇒ Array<String>
Returns currencies served only annually (e.g. VND, RUB).
40 41 42 43 |
# File 'lib/timeprice/supported.rb', line 40 def annual_only_currencies manifest = DataLoader.load_manifest (manifest.dig("fx", "annual_only_currencies") || []).freeze end |
.countries ⇒ Array<String>
Returns frozen list of supported country codes.
18 19 20 |
# File 'lib/timeprice/supported.rb', line 18 def countries manifest_countries.map { |c| c["code"] }.freeze end |
.country?(country) ⇒ Boolean
65 66 67 |
# File 'lib/timeprice/supported.rb', line 65 def country?(country) countries.include?(country.to_s.upcase) end |
.country_for_currency(currency) ⇒ String?
Returns country code, or nil if unsupported.
77 78 79 |
# File 'lib/timeprice/supported.rb', line 77 def country_for_currency(currency) currency_to_country[currency.to_s.upcase] end |
.country_to_currency ⇒ Hash{String=>String}
Returns country code → currency code.
46 47 48 |
# File 'lib/timeprice/supported.rb', line 46 def country_to_currency manifest_countries.to_h { |c| [c["code"], c["currency"]] }.freeze end |
.currencies ⇒ Array<String>
Returns frozen list of supported currency codes (the FX base USD plus every currency the manifest declares).
24 25 26 27 |
# File 'lib/timeprice/supported.rb', line 24 def currencies base = DataLoader.load_manifest.dig("fx", "base") ([base] + DataLoader.load_manifest.dig("fx", "currencies")).uniq.freeze end |
.currency?(currency) ⇒ Boolean
71 72 73 |
# File 'lib/timeprice/supported.rb', line 71 def currency?(currency) currencies.include?(currency.to_s.upcase) end |
.currency_for_country(country) ⇒ String?
Returns currency code, or nil if unsupported.
83 84 85 |
# File 'lib/timeprice/supported.rb', line 83 def currency_for_country(country) country_to_currency[country.to_s.upcase] end |
.currency_to_country ⇒ Hash{String=>String}
Returns currency code → country code.
51 52 53 |
# File 'lib/timeprice/supported.rb', line 51 def currency_to_country country_to_currency.invert.freeze end |
.daily_currencies ⇒ Array<String>
Returns currencies with daily FX observations.
30 31 32 33 34 35 36 37 |
# File 'lib/timeprice/supported.rb', line 30 def daily_currencies manifest = DataLoader.load_manifest list = manifest.dig("fx", "daily_currencies") return currencies if list.nil? base = manifest.dig("fx", "base") ([base] + list).uniq.freeze end |
.decimals_for(currency) ⇒ Integer
ISO 4217 minor-unit count for a currency. Falls back to 2 for unknown codes so callers can still render some value rather than crashing.
59 60 61 |
# File 'lib/timeprice/supported.rb', line 59 def decimals_for(currency) ZERO_DECIMAL_CURRENCIES.include?(currency.to_s.upcase) ? 0 : 2 end |