Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adapting currency data from the currencies gem to supplement the CLDR…

… data
  • Loading branch information...
commit ee8d5b2f023cfc811699be78af17821a162453ac 1 parent dbf4535
Cameron Dutro authored
View
30 NOTICE
@@ -151,4 +151,32 @@ OR PERFORMANCE OF THIS SOFTWARE.
Except as contained in this notice, the name of a copyright holder shall not be
used in advertising or otherwise to promote the sale, use or other dealings in
-this Software without prior written authorization of the copyright holder.
+this Software without prior written authorization of the copyright holder.
+
+
+
+
+
+The currencies data in twitter-cldr-rb has been adapted from the currencies gem.
+Here's the license that accompanied that code:
+
+Copyright (c) 2009 hexorx
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
11 README.md
@@ -42,7 +42,6 @@ TwitterCldr patches core Ruby objects like `Fixnum` and `Date` to make localizat
# currencies, default USD
1337.localize(:es).to_currency.to_s # 1.337,00 $
1337.localize(:es).to_currency.to_s(:currency => "EUR") # 1.337,00 €
-1337.localize(:es).to_currency.to_s(:currency => "Peru") # 1.337,00 S/.
# percentages
1337.localize(:es).to_percent.to_s # 1.337%
@@ -63,20 +62,14 @@ num.to_currency.to_s # ...etc
#### More on Currencies
-If you're looking for a list of supported countries and currencies, use the `TwitterCldr::Shared::Currencies` class:
+If you're looking for a list of supported currencies, use the `TwitterCldr::Shared::Currencies` class:
```ruby
-# all supported countries
-TwitterCldr::Shared::Currencies.countries # ["Lithuania", "Philippines", ... ]
-
# all supported currency codes
TwitterCldr::Shared::Currencies.currency_codes # ["LTL", "PHP" ... ]
-# data for a specific country
-TwitterCldr::Shared::Currencies.for_country("Canada") # { :currency => "Dollar", :symbol => "$", :code => "CAD" }
-
# data for a specific currency code
-TwitterCldr::Shared::Currencies.for_code("CAD") # { :currency => "Dollar", :symbol => "$", :country => "Canada"}
+TwitterCldr::Shared::Currencies.for_code("CAD") # { :currency => "Canadian dollar", :symbol => "$", :cldr_symbol => "CA$", :country => "Canada" }
```
#### Short / Long Decimals
View
15 lib/twitter_cldr/formatters/numbers/currency_formatter.rb
@@ -12,17 +12,26 @@ class CurrencyFormatter < NumberFormatter
def format(number, options = {})
options[:currency] ||= "USD"
currency = TwitterCldr::Shared::Currencies.for_code(options[:currency])
- currency ||= TwitterCldr::Shared::Currencies.for_country(options[:currency])
- currency ||= { :symbol => options[:currency], :currency => options[:currency] }
+ currency ||= {
+ :currency => options[:currency],
+ :symbol => options[:currency],
+ :cldr_symbol => options[:currency]
+ }
+
+ # overwrite with explicit symbol if given
+ currency[:symbol] = options[:symbol] if options[:symbol]
digits_and_rounding = resource(options[:currency])
options[:precision] ||= digits_and_rounding[:digits]
options[:rounding] ||= digits_and_rounding[:rounding]
- super(number, options).gsub('¤', (currency[:symbol] || currency[:currency].to_s))
+ symbol = options[:use_cldr_symbol] ? currency[:cldr_symbol] : currency[:symbol]
+ symbol ||= currency[:currency].to_s
+ super(number, options).gsub('¤', symbol)
end
private
+
def resource(code)
@resource ||= TwitterCldr.get_resource(:shared, :currency_digits_and_rounding)
@resource[code.to_sym] || @resource[:DEFAULT]
View
32 lib/twitter_cldr/shared/currencies.rb
@@ -7,32 +7,34 @@ 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
+ symbol_data = iso_currency_symbols[currency_code]
+
+ if data
+ result = {
+ :currency => currency_code,
+ :name => data[:one],
+ :cldr_symbol => data[:symbol],
+ :symbol => data[:symbol]
+ }
+
+ result.merge!(symbol_data) if symbol_data
+ end
+
+ result
end
private
- def resource_countries
- @resource_countries ||= TwitterCldr.get_resource(:shared, :currencies)
+ # ISO 4217 to be precise
+ def iso_currency_symbols
+ @iso_currency_symbols ||= TwitterCldr.get_resource(:shared, :iso_currency_symbols)
end
def resource(locale)
View
448 resources/shared/currencies.yml
@@ -1,448 +0,0 @@
-:Afghanistan:
- :code: AFN
- :currency: Afghani
- :symbol: ؋
-:Albania:
- :code: ALL
- :currency: Lek
- :symbol: Lek
-:Argentina:
- :code: ARS
- :currency: Peso
- :symbol: $
-:Aruba:
- :code: AWG
- :currency: Guilder
- :symbol: ƒ
-:Australia:
- :code: AUD
- :currency: Dollar
- :symbol: $
-:Azerbaijan:
- :code: AZN
- :currency: New Manat
- :symbol: ман
-:Bahamas:
- :code: BSD
- :currency: Dollar
- :symbol: $
-:Barbados:
- :code: BBD
- :currency: Dollar
- :symbol: $
-:Belarus:
- :code: BYR
- :currency: Ruble
- :symbol: p.
-:Belize:
- :code: BZD
- :currency: Dollar
- :symbol: BZ$
-:Bermuda:
- :code: BMD
- :currency: Dollar
- :symbol: $
-:Bolivia:
- :code: BOB
- :currency: Boliviano
- :symbol: $b
-:Bosnia and Herzegovina:
- :code: BAM
- :currency: Convertible Marka
- :symbol: KM
-:Botswana:
- :code: BWP
- :currency: Pula
- :symbol: P
-:Brazil:
- :code: BRL
- :currency: Real
- :symbol: R$
-:Brunei Darussalam:
- :code: BND
- :currency: Dollar
- :symbol: $
-:Bulgaria:
- :code: BGN
- :currency: Lev
- :symbol: лв
-:Cambodia:
- :code: KHR
- :currency: Riel
- :symbol:
-:Canada:
- :code: CAD
- :currency: Dollar
- :symbol: $
-:Cayman Islands:
- :code: KYD
- :currency: Dollar
- :symbol: $
-:Chile:
- :code: CLP
- :currency: Peso
- :symbol: $
-:China:
- :code: CNY
- :currency: Yuan Renminbi
- :symbol: ¥
-:Colombia:
- :code: COP
- :currency: Peso
- :symbol: $
-:Costa Rica:
- :code: CRC
- :currency: Colon
- :symbol:
-:Croatia:
- :code: HRK
- :currency: Kuna
- :symbol: kn
-:Cuba:
- :code: CUP
- :currency: Peso
- :symbol:
-:Czech Republic:
- :code: CZK
- :currency: Koruna
- :symbol:
-:Denmark:
- :code: DKK
- :currency: Krone
- :symbol: kr
-:Dominican Republic:
- :code: DOP
- :currency: Peso
- :symbol: RD$
-:East Caribbean:
- :code: XCD
- :currency: Dollar
- :symbol: $
-:Egypt:
- :code: EGP
- :currency: Pound
- :symbol: £
-:El Salvador:
- :code: SVC
- :currency: Colon
- :symbol: $
-:Estonia:
- :code: EEK
- :currency: Kroon
- :symbol: kr
-:Euro Member Countries:
- :code: EUR
- :currency: European Union
- :symbol:
-:Falkland Islands (Malvinas):
- :code: FKP
- :currency: Pound
- :symbol: £
-:Fiji:
- :code: FJD
- :currency: Dollar
- :symbol: $
-:Ghana:
- :code: GHC
- :currency: Cedis
- :symbol: ¢
-:Gibraltar:
- :code: GIP
- :currency: Pound
- :symbol: £
-:Guatemala:
- :code: GTQ
- :currency: Quetzal
- :symbol: Q
-:Guernsey:
- :code: GGP
- :currency: Pound
- :symbol: £
-:Guyana:
- :code: GYD
- :currency: Dollar
- :symbol: $
-:Honduras:
- :code: HNL
- :currency: Lempira
- :symbol: L
-:Hong Kong:
- :code: HKD
- :currency: Dollar
- :symbol: $
-:Hungary:
- :code: HUF
- :currency: Forint
- :symbol: Ft
-:Iceland:
- :code: ISK
- :currency: Krona
- :symbol: kr
-:India:
- :code: INR
- :currency: Rupee
- :symbol:
-:Indonesia:
- :code: IDR
- :currency: Rupiah
- :symbol: Rp
-:Iran:
- :code: IRR
- :currency: Rial
- :symbol:
-:Isle of Man:
- :code: IMP
- :currency: Pound
- :symbol: £
-:Israel:
- :code: ILS
- :currency: Shekel
- :symbol:
-:Jamaica:
- :code: JMD
- :currency: Dollar
- :symbol: J$
-:Japan:
- :code: JPY
- :currency: Yen
- :symbol: ¥
-:Jersey:
- :code: JEP
- :currency: Pound
- :symbol: £
-:Kazakhstan:
- :code: KZT
- :currency: Tenge
- :symbol: лв
-:Kyrgyzstan:
- :code: KGS
- :currency: Som
- :symbol: лв
-:Laos:
- :code: LAK
- :currency: Kip
- :symbol:
-:Latvia:
- :code: LVL
- :currency: Lat
- :symbol: Ls
-:Lebanon:
- :code: LBP
- :currency: Pound
- :symbol: £
-:Liberia:
- :code: LRD
- :currency: Dollar
- :symbol: $
-:Lithuania:
- :code: LTL
- :currency: Litas
- :symbol: Lt
-:Macedonia:
- :code: MKD
- :currency: Denar
- :symbol: ден
-:Malaysia:
- :code: MYR
- :currency: Ringgit
- :symbol: RM
-:Mauritius:
- :code: MUR
- :currency: Rupee
- :symbol:
-:Mexico:
- :code: MXN
- :currency: Peso
- :symbol: $
-:Mongolia:
- :code: MNT
- :currency: Tughrik
- :symbol:
-:Mozambique:
- :code: MZN
- :currency: Metical
- :symbol: MT
-:Namibia:
- :code: NAD
- :currency: Dollar
- :symbol: $
-:Nepal:
- :code: NPR
- :currency: Rupee
- :symbol:
-:Netherlands Antilles:
- :code: ANG
- :currency: Guilder
- :symbol: ƒ
-:New Zealand:
- :code: NZD
- :currency: Dollar
- :symbol: $
-:Nicaragua:
- :code: NIO
- :currency: Cordoba
- :symbol: C$
-:Nigeria:
- :code: NGN
- :currency: Naira
- :symbol:
-:North Korea:
- :code: KPW
- :currency: Won
- :symbol:
-:Norway:
- :code: NOK
- :currency: Krone
- :symbol: kr
-:Oman:
- :code: OMR
- :currency: Rial
- :symbol:
-:Pakistan:
- :code: PKR
- :currency: Rupee
- :symbol:
-:Panama:
- :code: PAB
- :currency: Balboa
- :symbol: B/.
-:Paraguay:
- :code: PYG
- :currency: Guarani
- :symbol: Gs
-:Peru:
- :code: PEN
- :currency: Nuevo Sol
- :symbol: S/.
-:Philippines:
- :code: PHP
- :currency: Peso
- :symbol:
-:Poland:
- :code: PLN
- :currency: Zloty
- :symbol:
-:Qatar:
- :code: QAR
- :currency: Riyal
- :symbol:
-:Romania:
- :code: RON
- :currency: New Leu
- :symbol: lei
-:Russia:
- :code: RUB
- :currency: Ruble
- :symbol: руб
-:Saint Helena:
- :code: SHP
- :currency: Pound
- :symbol: £
-:Saudi Arabia:
- :code: SAR
- :currency: Riyal
- :symbol:
-:Serbia:
- :code: RSD
- :currency: Dinar
- :symbol: Дин.
-:Seychelles:
- :code: SCR
- :currency: Rupee
- :symbol:
-:Singapore:
- :code: SGD
- :currency: Dollar
- :symbol: $
-:Solomon Islands:
- :code: SBD
- :currency: Dollar
- :symbol: $
-:Somalia:
- :code: SOS
- :currency: Shilling
- :symbol: S
-:South Africa:
- :code: ZAR
- :currency: Rand
- :symbol: R
-:South Korea:
- :code: KRW
- :currency: Won
- :symbol:
-:Sri Lanka:
- :code: LKR
- :currency: Rupee
- :symbol:
-:Suriname:
- :code: SRD
- :currency: Dollar
- :symbol: $
-:Sweden:
- :code: SEK
- :currency: Krona
- :symbol: kr
-:Switzerland:
- :code: CHF
- :currency: Franc
- :symbol: CHF
-:Syria:
- :code: SYP
- :currency: Pound
- :symbol: £
-:Taiwan:
- :code: TWD
- :currency: New Dollar
- :symbol: NT$
-:Thailand:
- :code: THB
- :currency: Baht
- :symbol: ฿
-:Trinidad and Tobago:
- :code: TTD
- :currency: Dollar
- :symbol: TT$
-:Turkey:
- :code: TRY
- :currency: Lira
- :symbol:
-:Tuvalu:
- :code: TVD
- :currency: Dollar
- :symbol: $
-:Ukraine:
- :code: UAH
- :currency: Hryvna
- :symbol:
-:United Kingdom:
- :code: GBP
- :currency: Pound
- :symbol: £
-:United States:
- :code: USD
- :currency: Dollar
- :symbol: $
-:Uruguay:
- :code: UYU
- :currency: Peso
- :symbol: $U
-:Uzbekistan:
- :code: UZS
- :currency: Som
- :symbol: лв
-:Venezuela:
- :code: VEF
- :currency: Bolivar Fuerte
- :symbol: Bs
-:Viet Nam:
- :code: VND
- :currency: Dong
- :symbol:
-:Yemen:
- :code: YER
- :currency: Rial
- :symbol:
-:Zimbabwe:
- :code: ZWD
- :currency: Dollar
- :symbol: Z$
View
475 resources/shared/iso_currency_symbols.yml
@@ -0,0 +1,475 @@
+---
+:AFN:
+ :symbol: ؋
+ :unicode_hex:
+ - 1547
+:ALL:
+ :symbol: LEK
+ :unicode_hex:
+ - 76
+ - 101
+ - 107
+:ANG:
+ :symbol: ƒ
+ :unicode_hex:
+ - 402
+:ARS:
+ :symbol: $
+ :unicode_hex:
+ - 36
+:AUD:
+ :symbol: $
+ :unicode_hex:
+ - 36
+:AWG:
+ :alt_name: Florins
+ :symbol: ƒ
+ :unicode_hex:
+ - 402
+:AZN:
+ :symbol: ман
+ :unicode_hex:
+ - 1084
+ - 1072
+ - 1085
+:BAM:
+ :symbol: KM
+ :unicode_hex:
+ - 75
+ - 77
+:BBD:
+ :symbol: $
+ :unicode_hex:
+ - 36
+:BGN:
+ :symbol: лв
+ :unicode_hex:
+ - 82
+ - 1074
+:BMD:
+ :symbol: $
+ :unicode_hex:
+ - 36
+:BND:
+ :symbol: $
+ :unicode_hex:
+ - 36
+:BOB:
+ :symbol: $b
+ :unicode_hex:
+ - 36
+ - 98
+:BRL:
+ :symbol: R$
+ :unicode_hex:
+ - 82
+ - 36
+:BSD:
+ :symbol: $
+ :unicode_hex:
+ - 36
+:BWP:
+ :symbol: P
+ :unicode_hex:
+ - 80
+:BYR:
+ :symbol: p.
+ :unicode_hex:
+ - 112
+ - 46
+:BZD:
+ :symbol: BZ$
+ :unicode_hex:
+ - 66
+ - 90
+ - 36
+:CAD:
+ :symbol: $
+ :unicode_hex:
+ - 36
+:CHF:
+ :symbol: CHF
+ :unicode_hex:
+ - 67
+ - 72
+ - 70
+:CLP:
+ :symbol: $
+ :unicode_hex:
+ - 36
+:CNY:
+ :symbol: ¥
+ :unicode_hex:
+ - 165
+:COP:
+ :symbol: $
+ :unicode_hex:
+ - 36
+:CRC:
+ :symbol:
+ :unicode_hex:
+ - 8353
+:CUP:
+ :symbol:
+ :unicode_hex:
+ - 8369
+:CZK:
+ :symbol:
+ :unicode_hex:
+ - 75
+ - 269
+:DKK:
+ :symbol: kr
+ :unicode_hex:
+ - 107
+ - 114
+:DOP:
+ :symbol: RD$
+ :unicode_hex:
+ - 82
+ - 68
+ - 36
+:EEK:
+ :symbol: kr
+ :unicode_hex:
+ - 107
+ - 114
+:EGP:
+ :symbol: £
+ :unicode_hex:
+ - 163
+:EUR:
+ :symbol:
+ :unicode_hex:
+ - 8364
+:FKP:
+ :symbol: £
+ :unicode_hex:
+ - 163
+:GBP:
+ :symbol: £
+ :unicode_hex:
+ - 163
+:GGP:
+ :symbol: £
+ :unicode_hex:
+ - 163
+:GHS:
+ :symbol: ¢
+ :unicode_hex:
+ - 162
+:GIP:
+ :symbol: £
+ :unicode_hex:
+ - 163
+:GTQ:
+ :symbol: Q
+ :unicode_hex:
+ - 81
+:HKD:
+ :symbol: $
+ :unicode_hex:
+ - 36
+:HNL:
+ :symbol: L
+ :unicode_hex:
+ - 76
+:HRK:
+ :symbol: kn
+ :unicode_hex:
+ - 107
+ - 110
+:HUF:
+ :symbol: Ft
+ :unicode_hex:
+ - 70
+ - 116
+:IDR:
+ :symbol: Rp
+ :unicode_hex:
+ - 82
+ - 112
+:ILS:
+ :symbol:
+ :unicode_hex:
+ - 8362
+:IMP:
+ :symbol: £
+ :unicode_hex:
+ - 163
+:INR:
+ :symbol:
+ :unicode_hex:
+ - 8360
+:IRR:
+ :symbol:
+ :unicode_hex:
+ - 65020
+:ISK:
+ :symbol: kr
+ :unicode_hex:
+ - 107
+ - 114
+:JEP:
+ :symbol: £
+ :unicode_hex:
+ - 163
+:JPY:
+ :symbol: ¥
+ :unicode_hex:
+ - 165
+:KGS:
+ :symbol: лв
+ :unicode_hex:
+ - 1083
+ - 1074
+:KPW:
+ :symbol:
+ :unicode_hex:
+ - 8361
+:KRW:
+ :symbol:
+ :unicode_hex:
+ - 8361
+:KYD:
+ :symbol: $
+ :unicode_hex:
+ - 36
+:KZT:
+ :symbol: лв
+ :unicode_hex:
+ - 1083
+ - 1074
+:LAK:
+ :symbol:
+ :unicode_hex:
+ - 8365
+:LBP:
+ :symbol: £
+ :unicode_hex:
+ - 163
+:LKR:
+ :symbol:
+ :unicode_hex:
+ - 8360
+:LRD:
+ :symbol: $
+ :unicode_hex:
+ - 36
+:LTL:
+ :symbol: Lt
+ :unicode_hex:
+ - 76
+ - 116
+:LVL:
+ :symbol: Ls
+ :unicode_hex:
+ - 76
+ - 115
+:MNT:
+ :symbol:
+ :unicode_hex:
+ - 8366
+:MUR:
+ :symbol:
+ :unicode_hex:
+ - 8360
+:MXN:
+ :symbol: $
+ :unicode_hex:
+ - 36
+:MYR:
+ :symbol: RM
+ :unicode_hex:
+ - 82
+ - 77
+:MZN:
+ :symbol: MT
+ :unicode_hex:
+ - 77
+ - 84
+:NAD:
+ :symbol: $
+ :unicode_hex:
+ - 36
+:NGN:
+ :symbol:
+ :unicode_hex:
+ - 8358
+:NIO:
+ :symbol: C$
+ :unicode_hex:
+ - 67
+ - 36
+:NOK:
+ :symbol: kr
+ :unicode_hex:
+ - 123
+ - 114
+:NPR:
+ :symbol:
+ :unicode_hex:
+ - 8360
+:NZD:
+ :symbol: $
+ :unicode_hex:
+ - 36
+:OMR:
+ :symbol:
+ :unicode_hex:
+ - 65020
+:PAB:
+ :symbol: B/.
+ :unicode_hex:
+ - 66
+ - 47
+ - 46
+:PEN:
+ :symbol: S/.
+ :unicode_hex:
+ - 83
+ - 47
+ - 46
+:PHP:
+ :symbol: Php
+ :unicode_hex:
+ - 80
+ - 104
+ - 112
+:PKR:
+ :symbol:
+ :unicode_hex:
+ - 8360
+:PLN:
+ :symbol:
+ :unicode_hex:
+ - 122
+ - 322
+:PYG:
+ :symbol: Gs
+ :unicode_hex:
+ - 71
+ - 115
+:QAR:
+ :symbol:
+ :unicode_hex:
+ - 65020
+:RON:
+ :symbol: lei
+ :unicode_hex:
+ - 108
+ - 101
+ - 105
+:RSD:
+ :symbol: Дин.
+ :unicode_hex:
+ - 1044
+ - 1080
+ - 1085
+ - 46
+:RUB:
+ :symbol: руб
+ :unicode_hex:
+ - 1088
+ - 1091
+ - 1073
+:SAR:
+ :symbol:
+ :unicode_hex:
+ - 65020
+:SBD:
+ :symbol: $
+ :unicode_hex:
+ - 36
+:SCR:
+ :symbol:
+ :unicode_hex:
+ - 8360
+:SEK:
+ :symbol: kr
+ :unicode_hex:
+ - 107
+ - 114
+:SGD:
+ :symbol: $
+ :unicode_hex:
+ - 36
+:SHP:
+ :symbol: £
+ :unicode_hex:
+ - 163
+:SOS:
+ :symbol: S
+ :unicode_hex:
+ - 83
+:SRD:
+ :symbol: $
+ :unicode_hex:
+ - 36
+:SYP:
+ :symbol: £
+ :unicode_hex:
+ - 163
+:THB:
+ :symbol: ฿
+ :unicode_hex:
+ - 3647
+:TRY:
+ :symbol: TL
+ :unicode_hex:
+ - 84
+ - 76
+:TTD:
+ :symbol: $
+ :unicode_hex:
+ - 36
+:TWD:
+ :symbol: NT$
+ :unicode_hex:
+ - 78
+ - 84
+ - 36
+:UAH:
+ :symbol:
+ :unicode_hex:
+ - 8372
+:USD:
+ :symbol: $
+ :unicode_hex:
+ - 36
+:UYU:
+ :symbol: $U
+ :unicode_hex:
+ - 36
+ - 85
+:UZS:
+ :symbol: лв
+ :unicode_hex:
+ - 1083
+ - 1074
+:VEF:
+ :symbol: Bs
+ :unicode_hex:
+ - 1083
+ - 1074
+:VND:
+ :symbol:
+ :unicode_hex:
+ - 8363
+:XCD:
+ :symbol: $
+ :unicode_hex:
+ - 36
+:YER:
+ :symbol:
+ :unicode_hex:
+ - 65020
+:ZAR:
+ :symbol: R
+ :unicode_hex:
+ - 82
+:ZWD:
+ :symbol: Z$
+ :unicode_hex:
+ - 90
+ - 36
View
13 spec/formatters/numbers/currency_formatter_spec.rb
@@ -24,7 +24,16 @@
it "should use the specified currency symbol when specified" do
# S/. is the symbol for the Peruvian Nuevo Sol, just in case you were curious
- @formatter.format(12, :currency => "S/.").should == "S/.12.00"
+ @formatter.format(12, :symbol => "S/.").should == "S/.12.00"
+ end
+
+ it "should use the currency code as the symbol if the currency code can't be identified" do
+ @formatter.format(12, :currency => "XYZ").should == "XYZ12.00"
+ end
+
+ it "should respect the :use_cldr_symbol option" do
+ @formatter.format(12, :currency => "CAD").should == "$12.00"
+ @formatter.format(12, :currency => "CAD", :use_cldr_symbol => true).should == "CA$12.00"
end
it "should use the currency symbol for the corresponding currency code" do
@@ -35,7 +44,7 @@
@formatter.format(12, :precision => 3).should == "$12.000"
end
- it "should use the currency precision" do
+ it "should use the currency-specific default precision" do
@formatter.format(12, :currency => "TND").should == "TND12.000"
end
View
16 spec/readme_spec.rb
@@ -26,7 +26,6 @@ def spaces(str)
1337.localize(:es).to_s.should == "1.337"
spaces(1337.localize(:es).to_currency.to_s).should == "1.337,00 $"
spaces(1337.localize(:es).to_currency.to_s(:currency => "EUR").to_s).should == "1.337,00 €"
- spaces(1337.localize(:es).to_currency.to_s(:currency => "Peru").to_s).should == "1.337,00 PEN"
1337.localize(:es).to_percent.to_s.should == "1.337%"
1337.localize(:es).to_percent.to_s(:precision => 2).should == "1.337,00%"
1337.localize(:es).to_decimal.to_s(:precision => 3).should == "1.337,000"
@@ -36,18 +35,17 @@ def spaces(str)
end
it "verifies extra currency data" do
- countries = TwitterCldr::Shared::Currencies.countries
- countries.should be_a(Array)
- countries.should include("Lithuania")
- countries.should include("Philippines")
-
currency_codes = TwitterCldr::Shared::Currencies.currency_codes
currency_codes.should be_a(Array)
currency_codes.should include("LTL")
currency_codes.should include("PHP")
-
- TwitterCldr::Shared::Currencies.for_country("Canada").should == { :currency => :CAD, :symbol => "CA$", :name => "Canadian dollar"}
- TwitterCldr::Shared::Currencies.for_code("CAD").should == { :currency => :CAD, :symbol => "CA$", :name => "Canadian dollar"}
+ TwitterCldr::Shared::Currencies.for_code("CAD").should == {
+ :currency => :CAD,
+ :cldr_symbol => "CA$",
+ :symbol => "$",
+ :name => "Canadian dollar",
+ :unicode_hex=>[36]
+ }
end
it "verifies short and long decimals" do
View
37 spec/shared/currencies_spec.rb
@@ -11,15 +11,6 @@
TEST_CODES = %w[AUD THB RUB CNY JPY PEN ZAR INR KRW GBP]
describe Currencies do
- describe "#countries" do
- it "should list all supported countries" do
- countries = Currencies.countries
-
- countries.size.should == 112
- countries.should include(*TEST_COUNTRIES)
- end
- end
-
describe "#currency_codes" do
it "should list all supported country codes" do
codes = Currencies.currency_codes
@@ -29,28 +20,26 @@
end
end
- describe "#for_country" do
- it "should return all information for the given country" do
- data = Currencies.for_country("Peru")
-
+ describe "#for_code" do
+ it "should return all information for PEN" do
+ data = Currencies.for_code("PEN")
data.should be_a(Hash)
data.should include(
- :currency => :PEN,
- :name => "Peruvian nuevo sol",
- :symbol => nil
+ :name => "Peruvian nuevo sol",
+ :currency => :PEN,
+ :symbol => "S/.",
+ :cldr_symbol => nil
)
end
- end
-
- describe "#for_code" do
- it "should return all information for the given currency code" do
- data = Currencies.for_code("PEN")
+ it "should return all information for CAD, a currency code with multiple possible symbols" do
+ data = Currencies.for_code("CAD")
data.should be_a(Hash)
data.should include(
- :name => "Peruvian nuevo sol",
- :currency => :PEN,
- :symbol => nil
+ :name => "Canadian dollar",
+ :currency => :CAD,
+ :symbol => "$",
+ :cldr_symbol => "CA$"
)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.