-
Notifications
You must be signed in to change notification settings - Fork 93
/
currencies.rb
46 lines (38 loc) · 1.37 KB
/
currencies.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# encoding: UTF-8
# Copyright 2012 Twitter, Inc
# http://www.apache.org/licenses/LICENSE-2.0
module TwitterCldr
module Shared
module Currencies
class << self
def countries
Kernel.warn("Currencies#countries will be deprecated. Please use Currencies#for_code.")
resource_countries.keys.map(&:to_s)
end
def currency_codes(locale = :en)
resource(locale).keys.map { |c| c.to_s }
end
def for_country(country_name, locale = :en)
Kernel.warn("Currencies#for_country will be deprecated. Please use Currencies#for_code.")
for_code(resource_countries[country_name.to_sym][:code], locale) if resource_countries[country_name.to_sym]
end
def for_code(currency_code, locale = :en)
currency_code = currency_code.to_sym
data = resource(locale)[currency_code]
{ :currency => currency_code,
:name => data[:one],
:symbol => data[:symbol] } if data
end
private
def resource_countries
@resource_countries ||= TwitterCldr.get_resource(:shared, :currencies)
end
def resource(locale)
locale = locale.to_sym
@resource ||= {}
@resource[locale] ||= TwitterCldr.get_resource(:locales, locale, :currencies)[locale][:currencies]
end
end
end
end
end