Class: Num2words::Config
- Inherits:
-
Object
- Object
- Num2words::Config
- Defined in:
- lib/num2words/config.rb
Instance Attribute Summary collapse
-
#currency_warnings ⇒ Object
Returns the value of attribute currency_warnings.
Instance Method Summary collapse
- #available_currencies(locale = I18n.locale) ⇒ Object
- #default_currency(locale = nil, currency = nil) ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #reset!(locale = nil) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
7 8 9 |
# File 'lib/num2words/config.rb', line 7 def initialize reset! end |
Instance Attribute Details
#currency_warnings ⇒ Object
Returns the value of attribute currency_warnings.
5 6 7 |
# File 'lib/num2words/config.rb', line 5 def currency_warnings @currency_warnings end |
Instance Method Details
#available_currencies(locale = I18n.locale) ⇒ Object
26 27 28 |
# File 'lib/num2words/config.rb', line 26 def available_currencies(locale = I18n.locale) I18n.t("num2words.currencies", locale: locale).keys.map(&:to_sym) end |
#default_currency(locale = nil, currency = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/num2words/config.rb', line 11 def default_currency(locale = nil, currency = nil) if currency currency = currency.to_s.upcase.to_sym available = available_currencies(locale) if available.include?(currency) locale ? @local_currency[locale] = currency : @global_currency = currency elsif currency_warnings warn I18n.t("num2words.warnings.currency_not_available", lang: locale, currency: currency, locale: locale) end end locale ? (@local_currency[locale] || available_currencies(locale).first || @global_currency) : @global_currency end |
#reset!(locale = nil) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/num2words/config.rb', line 30 def reset!(locale = nil) return @local_currency.delete(locale) if locale @global_currency = available_currencies.first @local_currency = {} @currency_warnings = true end |