rails_currency 1.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +19 -0
- data/LICENSE +22 -0
- data/README.md +60 -0
- data/Rakefile +1 -9
- data/lib/rails_currency.rb +3 -4
- data/lib/rails_currency/conversion_services/google.rb +199 -0
- data/lib/rails_currency/conversion_services/xe.rb +114 -0
- data/lib/rails_currency/convertor.rb +30 -16
- data/lib/rails_currency/version.rb +3 -0
- data/rails_currency.gemspec +24 -0
- data/test/rails_currency_test.rb +96 -0
- metadata +83 -55
- data/AUTHOR +0 -0
- data/History.txt +0 -0
- data/Manifest.txt +0 -9
- data/README.txt +0 -124
- data/lib/rails_currency/constants.rb +0 -91
- data/test/ts_convertor.rb +0 -20
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a38f349188223a8b23658830592bacd288ebbc39
|
4
|
+
data.tar.gz: ec5d31c0b639ee1ffe0730fa1fb3e51f1063be41
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c0671787047310e20b60724a129f5740e922f13bbde4e76f20e29f2a80e25f37c7aa56c8d54a298f3380f555d500ff9051ba9a34f7b0a05b7085344b6cb27823
|
7
|
+
data.tar.gz: e44e18d88d5085b40ef72a733a979792ff59ca83feb22c57dab1f159bd3a93a46eba9a1badf4e404f1c4519c49654dc8509d5a6fbe0bf1e95dce77b6f3f26a45
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rails_currency (2.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
hpricot (0.8.6)
|
10
|
+
rake (10.3.2)
|
11
|
+
|
12
|
+
PLATFORMS
|
13
|
+
ruby
|
14
|
+
|
15
|
+
DEPENDENCIES
|
16
|
+
bundler (~> 1.7)
|
17
|
+
hpricot
|
18
|
+
rails_currency!
|
19
|
+
rake (~> 10.0)
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Allerin
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# RailsCurrency
|
2
|
+
|
3
|
+
A Ruby gem to real time convert among different currencies with services from xe.com and google.com
|
4
|
+
This gem is upgraded version of http://rubygems.org/gems/rails_currency/versions/1.2 and https://github.com/helloween/rails_currency
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'rails_currency'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install rails_currency
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
To get supported currencies
|
25
|
+
```ruby
|
26
|
+
# For google supported currencies
|
27
|
+
RailsCurrency::Convertor::Google::CURRENCIES
|
28
|
+
# For xe supported currencies
|
29
|
+
RailsCurrency::Convertor::Xe::CURRENCIES
|
30
|
+
```
|
31
|
+
To get rate
|
32
|
+
```ruby
|
33
|
+
# By default it will use service from google
|
34
|
+
RailsCurrency::Convertor.get_rate('CNY', 'USD')
|
35
|
+
# To convert amount with google.com
|
36
|
+
RailsCurrency::Convertor.get_rate('CNY', 'USD', 'google')
|
37
|
+
RailsCurrency::Convertor::Google.get_rate('CNY', 'USD')
|
38
|
+
# To convert amount with xe.com
|
39
|
+
RailsCurrency::Convertor.get_rate('CNY', 'USD', 'xe')
|
40
|
+
RailsCurrency::Convertor::Xe.get_rate('CNY', 'USD')
|
41
|
+
```
|
42
|
+
To convert an amount
|
43
|
+
```ruby
|
44
|
+
# By default it will use service from google
|
45
|
+
RailsCurrency::Convertor.convert(100, 'CNY', 'USD')
|
46
|
+
# To convert amount with google.com
|
47
|
+
RailsCurrency::Convertor.convert(100, 'CNY', 'USD', 'google')
|
48
|
+
RailsCurrency::Convertor::Google.convert(100, 'CNY', 'USD')
|
49
|
+
# To convert amount with xe.com
|
50
|
+
RailsCurrency::Convertor.convert(100, 'CNY', 'USD', 'xe')
|
51
|
+
RailsCurrency::Convertor::Xe.convert(100, 'CNY', 'USD')
|
52
|
+
```
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
1. Fork it ( https://github.com/allerin/rails_currency/fork )
|
57
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
58
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
59
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
60
|
+
5. Create a new Pull Request
|
data/Rakefile
CHANGED
@@ -1,10 +1,2 @@
|
|
1
|
-
require
|
2
|
-
require 'hoe'
|
1
|
+
require "bundler/gem_tasks"
|
3
2
|
|
4
|
-
Hoe.new('rails_currency', '1.2') do |p|
|
5
|
-
p.author = 'Naveen Joshi'
|
6
|
-
p.email = 'joshinav@gmail.com'
|
7
|
-
p.url = ''
|
8
|
-
p.summary = 'Real time currency converter for ruby'
|
9
|
-
p.description = 'A ruby lib to real time convert among different currencies'
|
10
|
-
end
|
data/lib/rails_currency.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'rails_currency/version'
|
2
|
+
require 'rails_currency/convertor'
|
3
3
|
|
4
|
-
RailsCurrency
|
5
|
-
extend RailsCurrency::Constants
|
4
|
+
module RailsCurrency
|
6
5
|
end
|
@@ -0,0 +1,199 @@
|
|
1
|
+
module RailsCurrency
|
2
|
+
class Convertor
|
3
|
+
class Google
|
4
|
+
|
5
|
+
CURRENCIES = {
|
6
|
+
'AED' => 'United Arab Emirates Dirham (AED)',
|
7
|
+
'AFN' => 'Afghan Afghani (AFN)',
|
8
|
+
'ALL' => 'Albanian Lek (ALL)',
|
9
|
+
'AMD' => 'Armenian Dram (AMD)',
|
10
|
+
'ANG' => 'Netherlands Antillean Guilder (ANG)',
|
11
|
+
'AOA' => 'Angolan Kwanza (AOA)',
|
12
|
+
'ARS' => 'Argentine Peso (ARS)',
|
13
|
+
'AUD' => 'Australian Dollar (A$)',
|
14
|
+
'AWG' => 'Aruban Florin (AWG)',
|
15
|
+
'AZN' => 'Azerbaijani Manat (AZN)',
|
16
|
+
'BAM' => 'Bosnia-Herzegovina Convertible Mark (BAM)',
|
17
|
+
'BBD' => 'Barbadian Dollar (BBD)',
|
18
|
+
'BDT' => 'Bangladeshi Taka (BDT)',
|
19
|
+
'BGN' => 'Bulgarian Lev (BGN)',
|
20
|
+
'BHD' => 'Bahraini Dinar (BHD)',
|
21
|
+
'BIF' => 'Burundian Franc (BIF)',
|
22
|
+
'BMD' => 'Bermudan Dollar (BMD)',
|
23
|
+
'BND' => 'Brunei Dollar (BND)',
|
24
|
+
'BOB' => 'Bolivian Boliviano (BOB)',
|
25
|
+
'BRL' => 'Brazilian Real (R$)',
|
26
|
+
'BSD' => 'Bahamian Dollar (BSD)',
|
27
|
+
'BTC' => 'Bitcoin (฿)',
|
28
|
+
'BTN' => 'Bhutanese Ngultrum (BTN)',
|
29
|
+
'BWP' => 'Botswanan Pula (BWP)',
|
30
|
+
'BYR' => 'Belarusian Ruble (BYR)',
|
31
|
+
'BZD' => 'Belize Dollar (BZD)',
|
32
|
+
'CAD' => 'Canadian Dollar (CA$)',
|
33
|
+
'CDF' => 'Congolese Franc (CDF)',
|
34
|
+
'CHF' => 'Swiss Franc (CHF)',
|
35
|
+
'CLF' => 'Chilean Unit of Account (UF) (CLF)',
|
36
|
+
'CLP' => 'Chilean Peso (CLP)',
|
37
|
+
'CNH' => 'CNH (CNH)',
|
38
|
+
'CNY' => 'Chinese Yuan (CN¥)',
|
39
|
+
'COP' => 'Colombian Peso (COP)',
|
40
|
+
'CRC' => 'Costa Rican Colón (CRC)',
|
41
|
+
'CUP' => 'Cuban Peso (CUP)',
|
42
|
+
'CVE' => 'Cape Verdean Escudo (CVE)',
|
43
|
+
'CZK' => 'Czech Republic Koruna (CZK)',
|
44
|
+
'DEM' => 'German Mark (DEM)',
|
45
|
+
'DJF' => 'Djiboutian Franc (DJF)',
|
46
|
+
'DKK' => 'Danish Krone (DKK)',
|
47
|
+
'DOP' => 'Dominican Peso (DOP)',
|
48
|
+
'DZD' => 'Algerian Dinar (DZD)',
|
49
|
+
'EGP' => 'Egyptian Pound (EGP)',
|
50
|
+
'ERN' => 'Eritrean Nakfa (ERN)',
|
51
|
+
'ETB' => 'Ethiopian Birr (ETB)',
|
52
|
+
'EUR' => 'Euro (€)',
|
53
|
+
'FIM' => 'Finnish Markka (FIM)',
|
54
|
+
'FJD' => 'Fijian Dollar (FJD)',
|
55
|
+
'FKP' => 'Falkland Islands Pound (FKP)',
|
56
|
+
'FRF' => 'French Franc (FRF)',
|
57
|
+
'GBP' => 'British Pound Sterling (£)',
|
58
|
+
'GEL' => 'Georgian Lari (GEL)',
|
59
|
+
'GHS' => 'Ghanaian Cedi (GHS)',
|
60
|
+
'GIP' => 'Gibraltar Pound (GIP)',
|
61
|
+
'GMD' => 'Gambian Dalasi (GMD)',
|
62
|
+
'GNF' => 'Guinean Franc (GNF)',
|
63
|
+
'GTQ' => 'Guatemalan Quetzal (GTQ)',
|
64
|
+
'GYD' => 'Guyanaese Dollar (GYD)',
|
65
|
+
'HKD' => 'Hong Kong Dollar (HK$)',
|
66
|
+
'HNL' => 'Honduran Lempira (HNL)',
|
67
|
+
'HRK' => 'Croatian Kuna (HRK)',
|
68
|
+
'HTG' => 'Haitian Gourde (HTG)',
|
69
|
+
'HUF' => 'Hungarian Forint (HUF)',
|
70
|
+
'IDR' => 'Indonesian Rupiah (IDR)',
|
71
|
+
'IEP' => 'Irish Pound (IEP)',
|
72
|
+
'ILS' => 'Israeli New Sheqel (₪)',
|
73
|
+
'INR' => 'Indian Rupee (Rs.)',
|
74
|
+
'IQD' => 'Iraqi Dinar (IQD)',
|
75
|
+
'IRR' => 'Iranian Rial (IRR)',
|
76
|
+
'ISK' => 'Icelandic Króna (ISK)',
|
77
|
+
'ITL' => 'Italian Lira (ITL)',
|
78
|
+
'JMD' => 'Jamaican Dollar (JMD)',
|
79
|
+
'JOD' => 'Jordanian Dinar (JOD)',
|
80
|
+
'JPY' => 'Japanese Yen (¥)',
|
81
|
+
'KES' => 'Kenyan Shilling (KES)',
|
82
|
+
'KGS' => 'Kyrgystani Som (KGS)',
|
83
|
+
'KHR' => 'Cambodian Riel (KHR)',
|
84
|
+
'KMF' => 'Comorian Franc (KMF)',
|
85
|
+
'KPW' => 'North Korean Won (KPW)',
|
86
|
+
'KRW' => 'South Korean Won (₩)',
|
87
|
+
'KWD' => 'Kuwaiti Dinar (KWD)',
|
88
|
+
'KYD' => 'Cayman Islands Dollar (KYD)',
|
89
|
+
'KZT' => 'Kazakhstani Tenge (KZT)',
|
90
|
+
'LAK' => 'Laotian Kip (LAK)',
|
91
|
+
'LBP' => 'Lebanese Pound (LBP)',
|
92
|
+
'LKR' => 'Sri Lankan Rupee (LKR)',
|
93
|
+
'LRD' => 'Liberian Dollar (LRD)',
|
94
|
+
'LSL' => 'Lesotho Loti (LSL)',
|
95
|
+
'LTL' => 'Lithuanian Litas (LTL)',
|
96
|
+
'LVL' => 'Latvian Lats (LVL)',
|
97
|
+
'LYD' => 'Libyan Dinar (LYD)',
|
98
|
+
'MAD' => 'Moroccan Dirham (MAD)',
|
99
|
+
'MDL' => 'Moldovan Leu (MDL)',
|
100
|
+
'MGA' => 'Malagasy Ariary (MGA)',
|
101
|
+
'MKD' => 'Macedonian Denar (MKD)',
|
102
|
+
'MMK' => 'Myanmar Kyat (MMK)',
|
103
|
+
'MNT' => 'Mongolian Tugrik (MNT)',
|
104
|
+
'MOP' => 'Macanese Pataca (MOP)',
|
105
|
+
'MRO' => 'Mauritanian Ouguiya (MRO)',
|
106
|
+
'MUR' => 'Mauritian Rupee (MUR)',
|
107
|
+
'MVR' => 'Maldivian Rufiyaa (MVR)',
|
108
|
+
'MWK' => 'Malawian Kwacha (MWK)',
|
109
|
+
'MXN' => 'Mexican Peso (MX$)',
|
110
|
+
'MYR' => 'Malaysian Ringgit (MYR)',
|
111
|
+
'MZN' => 'Mozambican Metical (MZN)',
|
112
|
+
'NAD' => 'Namibian Dollar (NAD)',
|
113
|
+
'NGN' => 'Nigerian Naira (NGN)',
|
114
|
+
'NIO' => 'Nicaraguan Córdoba (NIO)',
|
115
|
+
'NOK' => 'Norwegian Krone (NOK)',
|
116
|
+
'NPR' => 'Nepalese Rupee (NPR)',
|
117
|
+
'NZD' => 'New Zealand Dollar (NZ$)',
|
118
|
+
'OMR' => 'Omani Rial (OMR)',
|
119
|
+
'PAB' => 'Panamanian Balboa (PAB)',
|
120
|
+
'PEN' => 'Peruvian Nuevo Sol (PEN)',
|
121
|
+
'PGK' => 'Papua New Guinean Kina (PGK)',
|
122
|
+
'PHP' => 'Philippine Peso (Php)',
|
123
|
+
'PKG' => 'PKG (PKG)',
|
124
|
+
'PKR' => 'Pakistani Rupee (PKR)',
|
125
|
+
'PLN' => 'Polish Zloty (PLN)',
|
126
|
+
'PYG' => 'Paraguayan Guarani (PYG)',
|
127
|
+
'QAR' => 'Qatari Rial (QAR)',
|
128
|
+
'RON' => 'Romanian Leu (RON)',
|
129
|
+
'RSD' => 'Serbian Dinar (RSD)',
|
130
|
+
'RUB' => 'Russian Ruble (RUB)',
|
131
|
+
'RWF' => 'Rwandan Franc (RWF)',
|
132
|
+
'SAR' => 'Saudi Riyal (SAR)',
|
133
|
+
'SBD' => 'Solomon Islands Dollar (SBD)',
|
134
|
+
'SCR' => 'Seychellois Rupee (SCR)',
|
135
|
+
'SDG' => 'Sudanese Pound (SDG)',
|
136
|
+
'SEK' => 'Swedish Krona (SEK)',
|
137
|
+
'SGD' => 'Singapore Dollar (SGD)',
|
138
|
+
'SHP' => 'Saint Helena Pound (SHP)',
|
139
|
+
'SLL' => 'Sierra Leonean Leone (SLL)',
|
140
|
+
'SOS' => 'Somali Shilling (SOS)',
|
141
|
+
'SRD' => 'Surinamese Dollar (SRD)',
|
142
|
+
'STD' => 'São Tomé and Príncipe Dobra (STD)',
|
143
|
+
'SVC' => 'Salvadoran Colón (SVC)',
|
144
|
+
'SYP' => 'Syrian Pound (SYP)',
|
145
|
+
'SZL' => 'Swazi Lilangeni (SZL)',
|
146
|
+
'THB' => 'Thai Baht (฿)',
|
147
|
+
'TJS' => 'Tajikistani Somoni (TJS)',
|
148
|
+
'TMT' => 'Turkmenistani Manat (TMT)',
|
149
|
+
'TND' => 'Tunisian Dinar (TND)',
|
150
|
+
'TOP' => 'Tongan Paʻanga (TOP)',
|
151
|
+
'TRY' => 'Turkish Lira (TRY)',
|
152
|
+
'TTD' => 'Trinidad and Tobago Dollar (TTD)',
|
153
|
+
'TWD' => 'New Taiwan Dollar (NT$)',
|
154
|
+
'TZS' => 'Tanzanian Shilling (TZS)',
|
155
|
+
'UAH' => 'Ukrainian Hryvnia (UAH)',
|
156
|
+
'UGX' => 'Ugandan Shilling (UGX)',
|
157
|
+
'USD' => 'US Dollar ($)',
|
158
|
+
'UYU' => 'Uruguayan Peso (UYU)',
|
159
|
+
'UZS' => 'Uzbekistan Som (UZS)',
|
160
|
+
'VEF' => 'Venezuelan Bolívar (VEF)',
|
161
|
+
'VND' => 'Vietnamese Dong (₫)',
|
162
|
+
'VUV' => 'Vanuatu Vatu (VUV)',
|
163
|
+
'WST' => 'Samoan Tala (WST)',
|
164
|
+
'XAF' => 'CFA Franc BEAC (FCFA)',
|
165
|
+
'XCD' => 'East Caribbean Dollar (EC$)',
|
166
|
+
'XDR' => 'Special Drawing Rights (XDR)',
|
167
|
+
'XOF' => 'CFA Franc BCEAO (CFA)',
|
168
|
+
'XPF' => 'CFP Franc (CFPF)',
|
169
|
+
'YER' => 'Yemeni Rial (YER)',
|
170
|
+
'ZAR' => 'South African Rand (ZAR)',
|
171
|
+
'ZMK' => 'Zambian Kwacha (1968-2012) (ZMK)',
|
172
|
+
'ZMW' => 'Zambian Kwacha (ZMW)',
|
173
|
+
'ZWL' => 'Zimbabwean Dollar (2009) (ZWL)'
|
174
|
+
}
|
175
|
+
class << self
|
176
|
+
|
177
|
+
def service_url
|
178
|
+
'http://www.google.com/finance/converter'
|
179
|
+
end
|
180
|
+
|
181
|
+
def convert(amount, from, to)
|
182
|
+
Convertor.convert(amount, from, to, 'google')
|
183
|
+
end
|
184
|
+
|
185
|
+
def process_request(amount, from, to)
|
186
|
+
url = "#{service_url}?a=#{amount}&from=#{from}&to=#{to}"
|
187
|
+
doc = open(url, Convertor::PARAMS) { |f| Hpricot(f) }
|
188
|
+
result = doc.search("//span[@class='bld']").inner_html.split(' ').first.to_f
|
189
|
+
end
|
190
|
+
|
191
|
+
def get_rate(from, to)
|
192
|
+
convert(1, from, to)
|
193
|
+
end
|
194
|
+
|
195
|
+
end
|
196
|
+
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
module RailsCurrency
|
2
|
+
class Convertor
|
3
|
+
class Xe
|
4
|
+
|
5
|
+
CURRENCIES = {
|
6
|
+
'AFN' => 'Afghanistan Afghanis',
|
7
|
+
'ALL' => 'Albania Leke',
|
8
|
+
'DZD' => 'Algeria Dinars',
|
9
|
+
'ARS' => 'Argentina Pesos',
|
10
|
+
'AUS' => 'Australia Dollars',
|
11
|
+
'BSD' => 'Bahamas Dollars',
|
12
|
+
'BHD' => 'Bahrain Dinars',
|
13
|
+
'BDT' => 'Bangladesh Taka',
|
14
|
+
'BBD' => 'Barbados Dollars',
|
15
|
+
'BMD' => 'Bermuda Dollars',
|
16
|
+
'BRL' => 'Brazil Reais',
|
17
|
+
'BGN' => 'Bulgaria Leva',
|
18
|
+
'XOF' => 'CFA BCEAO Francs',
|
19
|
+
'XAF' => 'CFA BEAC Francs',
|
20
|
+
'CAD' => 'Canada Dollars',
|
21
|
+
'CLP' => 'Chile Pesos',
|
22
|
+
'CNY' => 'China Yuan Renminbi',
|
23
|
+
'COP' => 'Colombia Pesos',
|
24
|
+
'XPF' => 'Comptoirs Français du Pacifique Francs',
|
25
|
+
'CRC' => 'Costa Rica Colones',
|
26
|
+
'HRK' => 'Croatia Kuna',
|
27
|
+
'CZK' => 'Czech Republic Koruny',
|
28
|
+
'DKK' => 'Denmark Kroner',
|
29
|
+
'DOP' => 'Dominican Republic Pesos',
|
30
|
+
'XCD' => 'East Caribbean Dollars',
|
31
|
+
'EGP' => 'Egypt Pounds',
|
32
|
+
'EEK' => 'Estonia Krooni',
|
33
|
+
'EUR' => 'Euro',
|
34
|
+
'FJD' => 'Fiji Dollars',
|
35
|
+
'XAU' => 'Gold Ounces',
|
36
|
+
'HKD' => 'Hong Kong Dollars',
|
37
|
+
'HUF' => 'Hungary Forint',
|
38
|
+
'XDR' => 'IMF Special Drawing Rights',
|
39
|
+
'ISK' => 'Iceland Kronur',
|
40
|
+
'INR' => 'India Rupees',
|
41
|
+
'IDR' => 'Indonesia Rupiahs',
|
42
|
+
'IRR' => 'Iran Rials',
|
43
|
+
'IQD' => 'Iraq Dinars',
|
44
|
+
'ILS' => 'Israel New Shekels',
|
45
|
+
'JMD' => 'Jamaica Dollars',
|
46
|
+
'JPY' => 'Japan Yen',
|
47
|
+
'JOD' => 'Jordan Dinars',
|
48
|
+
'KES' => 'Kenya Shillings',
|
49
|
+
'KWD' => 'Kuwait Dinars',
|
50
|
+
'LBP' => 'Lebanon Pounds',
|
51
|
+
'MYR' => 'Malaysia Ringgits',
|
52
|
+
'MUR' => 'Mauritius Rupees',
|
53
|
+
'MXN' => 'Mexico Pesos',
|
54
|
+
'MAD' => 'Morocco Dirhams',
|
55
|
+
'NZD' => 'New Zealand Dollars',
|
56
|
+
'NOK' => 'Norway Kroner',
|
57
|
+
'OMR' => 'Oman Rials',
|
58
|
+
'PKR' => 'Pakistan Rupees',
|
59
|
+
'XPD' => 'Palladium Ounces',
|
60
|
+
'PEN' => 'Peru Nuevos Soles',
|
61
|
+
'PHP' => 'Philippines Pesos',
|
62
|
+
'XPT' => 'Platinum Ounces',
|
63
|
+
'PLN' => 'Poland Zlotych',
|
64
|
+
'QAR' => 'Qatar Riyals',
|
65
|
+
'RON' => 'Romania New Lei',
|
66
|
+
'RUB' => 'Russia Rubles',
|
67
|
+
'SAR' => 'Saudi Arabia Riyals',
|
68
|
+
'XAG' => 'Silver Ounces',
|
69
|
+
'SGD' => 'Singapore Dollars',
|
70
|
+
'SKK' => 'Slovakia Koruny',
|
71
|
+
'ZAR' => 'South Africa Rand',
|
72
|
+
'KRW' => 'South Korea Won',
|
73
|
+
'LKR' => 'Sri Lanka Rupees',
|
74
|
+
'SDG' => 'Sudan Pounds',
|
75
|
+
'SEK' => 'Sweden Kronor',
|
76
|
+
'CHF' => 'Switzerland Francs',
|
77
|
+
'TWD' => 'Taiwan New Dollars',
|
78
|
+
'THB' => 'Thailand Baht',
|
79
|
+
'TTD' => 'Trinidad and Tobago Dollars',
|
80
|
+
'TND' => 'Tunisia Dinars',
|
81
|
+
'TRY' => 'Turkey New Lira',
|
82
|
+
'AED' => 'United Arab Emirates Dirhams',
|
83
|
+
'GBP' => 'United Kingdom Pounds',
|
84
|
+
'USD' => 'United States Dollars',
|
85
|
+
'VEF' => 'Venezuela Bolivares Fuertes',
|
86
|
+
'VND' => 'Vietnam Dong',
|
87
|
+
'ZMK' => 'Zambia Kwacha'
|
88
|
+
}
|
89
|
+
class << self
|
90
|
+
|
91
|
+
def service_url
|
92
|
+
'http://www.xe.com/currencyconverter/convert'
|
93
|
+
end
|
94
|
+
|
95
|
+
def convert(amount, from, to)
|
96
|
+
Convertor.convert(amount, from, to, 'xe')
|
97
|
+
end
|
98
|
+
|
99
|
+
def process_request(amount, from, to)
|
100
|
+
url = "#{service_url}?Amount=#{amount}&From=#{from}&To=#{to}"
|
101
|
+
doc = open(url, Convertor::PARAMS) { |f| Hpricot(f) }
|
102
|
+
result = doc.search("//table[@class='ucc-result-table']//tr[@class='uccResUnit']/td[@class='leftCol']")
|
103
|
+
result[0].inner_text.split('=')[1].gsub(/\s/, '').to_f
|
104
|
+
end
|
105
|
+
|
106
|
+
def get_rate(from, to)
|
107
|
+
convert(1, from, to)
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -1,15 +1,12 @@
|
|
1
1
|
require 'uri'
|
2
2
|
require 'open-uri'
|
3
3
|
require 'timeout'
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
rescue LoadError
|
8
|
-
require 'rubygems'
|
9
|
-
require 'hpricot'
|
10
|
-
end
|
4
|
+
require 'hpricot'
|
5
|
+
require 'rails_currency/conversion_services/google'
|
6
|
+
require 'rails_currency/conversion_services/xe'
|
11
7
|
|
12
8
|
module RailsCurrency
|
9
|
+
|
13
10
|
class RailsCurrencyError < StandardError
|
14
11
|
end
|
15
12
|
|
@@ -23,23 +20,40 @@ module RailsCurrency
|
|
23
20
|
end
|
24
21
|
|
25
22
|
class Convertor
|
23
|
+
|
24
|
+
PARAMS = {
|
25
|
+
'Connection' => 'Keep-Alive',
|
26
|
+
'Keep-Alive' => '30'
|
27
|
+
}
|
28
|
+
|
26
29
|
class << self
|
27
|
-
def convert(amount, from, to)
|
28
|
-
raise InvalidAmountError, "Only numeric value allowed" unless amount.is_a?(Numeric)
|
29
|
-
raise UnknownCurrencyError, "Unknown Currency" unless CurrencyList.key?(from.to_sym) && CurrencyList.key?(to.to_sym)
|
30
30
|
|
31
|
+
def convert(amount, from, to, service = 'google')
|
32
|
+
raise InvalidAmountError, 'Only numeric value allowed' unless amount.is_a?(Numeric)
|
33
|
+
unless conversion_service(service)::CURRENCIES.key?(from) && conversion_service(service)::CURRENCIES.key?(to)
|
34
|
+
raise UnknownCurrencyError, 'Unknown Currency'
|
35
|
+
end
|
31
36
|
begin
|
32
|
-
url = "#{CurrencyUrl}?Amount=#{amount}&From=#{from}&To=#{to}"
|
33
|
-
|
34
37
|
timeout(30) do
|
35
|
-
|
36
|
-
result = doc.search("//table[@class='XEtbl_sub']/tr/td[@id='XEenlarge']/h2[@class='XE']")[2].inner_text
|
37
|
-
result.gsub(",", "").scan(/\d+\.?\d+/).first.to_f
|
38
|
+
conversion_service(service).process_request(amount, from, to)
|
38
39
|
end
|
39
40
|
rescue TimeoutError
|
40
|
-
raise ServerTimeoutError, "Can't connect to server #{
|
41
|
+
raise ServerTimeoutError, "Can't connect to server #{service_url(service)}"
|
41
42
|
end
|
42
43
|
end
|
44
|
+
|
45
|
+
def service_url(service)
|
46
|
+
conversion_service(service).service_url
|
47
|
+
end
|
48
|
+
|
49
|
+
def get_rate(from, to, service = 'google')
|
50
|
+
conversion_service(service).get_rate(from, to)
|
51
|
+
end
|
52
|
+
|
53
|
+
def conversion_service(service_name)
|
54
|
+
service_name.downcase == 'xe' ? Convertor::Xe : Convertor::Google
|
55
|
+
end
|
56
|
+
|
43
57
|
end
|
44
58
|
end
|
45
59
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rails_currency/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rails_currency"
|
8
|
+
spec.version = RailsCurrency::VERSION
|
9
|
+
spec.authors = ['Allerin']
|
10
|
+
spec.email = ['services@allerin.com']
|
11
|
+
spec.summary = %q{A Ruby gem to real time convert among different currencies}
|
12
|
+
spec.description = %q{A Ruby gem to real time convert among different currencies with services from xe.com and google.com}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency 'hpricot'
|
24
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
2
|
+
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'rails_currency'
|
5
|
+
|
6
|
+
class RailsCurrencyTest < Minitest::Test
|
7
|
+
# Tests for Convertor
|
8
|
+
def test_convert
|
9
|
+
assert_kind_of Numeric, RailsCurrency::Convertor.convert(100, 'CNY', 'USD')
|
10
|
+
assert_kind_of Numeric, RailsCurrency::Convertor.convert(100, 'CNY', 'USD', 'google')
|
11
|
+
assert_kind_of Numeric, RailsCurrency::Convertor.convert(100, 'CNY', 'USD', 'xe')
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_invalid_convert
|
15
|
+
assert_raises RailsCurrency::InvalidAmountError do
|
16
|
+
RailsCurrency::Convertor.convert('100', 'CNY', 'USD')
|
17
|
+
end
|
18
|
+
assert_raises RailsCurrency::InvalidAmountError do
|
19
|
+
RailsCurrency::Convertor.convert('100', 'CNY', 'USD', 'google')
|
20
|
+
end
|
21
|
+
assert_raises RailsCurrency::InvalidAmountError do
|
22
|
+
RailsCurrency::Convertor.convert('100', 'CNY', 'USD', 'xe')
|
23
|
+
end
|
24
|
+
|
25
|
+
assert_raises RailsCurrency::UnknownCurrencyError do
|
26
|
+
RailsCurrency::Convertor.convert(100, 'CNY', 'ABC')
|
27
|
+
end
|
28
|
+
assert_raises RailsCurrency::UnknownCurrencyError do
|
29
|
+
RailsCurrency::Convertor.convert(100, 'CNY', 'ABC', 'google')
|
30
|
+
end
|
31
|
+
assert_raises RailsCurrency::UnknownCurrencyError do
|
32
|
+
RailsCurrency::Convertor.convert(100, 'CNY', 'ABC', 'xe')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_get_rate
|
37
|
+
assert_kind_of Numeric, RailsCurrency::Convertor.get_rate('CNY', 'USD')
|
38
|
+
assert_kind_of Numeric, RailsCurrency::Convertor.get_rate('CNY', 'USD', 'google')
|
39
|
+
assert_kind_of Numeric, RailsCurrency::Convertor.get_rate('CNY', 'USD', 'xe')
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_invalid_get_rate
|
43
|
+
assert_raises RailsCurrency::UnknownCurrencyError do
|
44
|
+
RailsCurrency::Convertor.get_rate('CNY', 'ABC')
|
45
|
+
end
|
46
|
+
assert_raises RailsCurrency::UnknownCurrencyError do
|
47
|
+
RailsCurrency::Convertor.get_rate('CNY', 'ABC', 'google')
|
48
|
+
end
|
49
|
+
assert_raises RailsCurrency::UnknownCurrencyError do
|
50
|
+
RailsCurrency::Convertor.get_rate('CNY', 'ABC', 'xe')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Tests for Convertor::Google
|
55
|
+
def test_convert_with_google
|
56
|
+
assert_kind_of Numeric, RailsCurrency::Convertor::Google.convert(100, 'CNY', 'USD')
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_invalid_convert_with_google
|
60
|
+
assert_raises RailsCurrency::InvalidAmountError do
|
61
|
+
RailsCurrency::Convertor::Google.convert('100', 'CNY', 'USD')
|
62
|
+
end
|
63
|
+
|
64
|
+
assert_raises RailsCurrency::UnknownCurrencyError do
|
65
|
+
RailsCurrency::Convertor::Google.convert(100, 'CNY', 'ABC')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_invalid_get_rate_with_google
|
70
|
+
assert_raises RailsCurrency::UnknownCurrencyError do
|
71
|
+
RailsCurrency::Convertor::Google.get_rate('CNY', 'ABC')
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Test for Convertor::Xe
|
76
|
+
def test_convert_with_xe
|
77
|
+
assert_kind_of Numeric, RailsCurrency::Convertor::Xe.convert(100, 'CNY', 'USD')
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_invalid_convert_with_xe
|
81
|
+
assert_raises RailsCurrency::InvalidAmountError do
|
82
|
+
RailsCurrency::Convertor::Xe.convert("100", 'CNY', 'USD')
|
83
|
+
end
|
84
|
+
|
85
|
+
assert_raises RailsCurrency::UnknownCurrencyError do
|
86
|
+
RailsCurrency::Convertor::Xe.convert(100, 'CNY', 'ABC')
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_invalid_get_rate_with_xe
|
91
|
+
assert_raises RailsCurrency::UnknownCurrencyError do
|
92
|
+
RailsCurrency::Convertor::Xe.get_rate('CNY', 'ABC')
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
metadata
CHANGED
@@ -1,72 +1,100 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_currency
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
7
|
-
-
|
6
|
+
authors:
|
7
|
+
- Allerin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
11
|
+
date: 2014-11-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: hpricot
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
20
45
|
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version:
|
23
|
-
|
24
|
-
|
25
|
-
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: A Ruby gem to real time convert among different currencies with services
|
56
|
+
from xe.com and google.com
|
57
|
+
email:
|
58
|
+
- services@allerin.com
|
26
59
|
executables: []
|
27
|
-
|
28
60
|
extensions: []
|
29
|
-
|
30
|
-
|
31
|
-
-
|
32
|
-
-
|
33
|
-
-
|
34
|
-
|
35
|
-
- AUTHOR
|
36
|
-
- History.txt
|
37
|
-
- Manifest.txt
|
38
|
-
- README.txt
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- Gemfile
|
64
|
+
- Gemfile.lock
|
65
|
+
- LICENSE
|
66
|
+
- README.md
|
39
67
|
- Rakefile
|
40
68
|
- lib/rails_currency.rb
|
41
|
-
- lib/rails_currency/
|
69
|
+
- lib/rails_currency/conversion_services/google.rb
|
70
|
+
- lib/rails_currency/conversion_services/xe.rb
|
42
71
|
- lib/rails_currency/convertor.rb
|
43
|
-
-
|
44
|
-
|
45
|
-
|
72
|
+
- lib/rails_currency/version.rb
|
73
|
+
- rails_currency.gemspec
|
74
|
+
- test/rails_currency_test.rb
|
75
|
+
homepage: ''
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
46
79
|
post_install_message:
|
47
|
-
rdoc_options:
|
48
|
-
|
49
|
-
- README.txt
|
50
|
-
require_paths:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
51
82
|
- lib
|
52
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
-
requirements:
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
54
85
|
- - ">="
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version:
|
57
|
-
|
58
|
-
|
59
|
-
requirements:
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
60
90
|
- - ">="
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version:
|
63
|
-
version:
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
64
93
|
requirements: []
|
65
|
-
|
66
|
-
|
67
|
-
rubygems_version: 1.0.1
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.4.4
|
68
96
|
signing_key:
|
69
|
-
specification_version:
|
70
|
-
summary:
|
71
|
-
test_files:
|
72
|
-
|
97
|
+
specification_version: 4
|
98
|
+
summary: A Ruby gem to real time convert among different currencies
|
99
|
+
test_files:
|
100
|
+
- test/rails_currency_test.rb
|
data/AUTHOR
DELETED
File without changes
|
data/History.txt
DELETED
File without changes
|
data/Manifest.txt
DELETED
data/README.txt
DELETED
@@ -1,124 +0,0 @@
|
|
1
|
-
= rcurrency
|
2
|
-
A ruby lib to real time convert among different currencies.
|
3
|
-
|
4
|
-
== Install
|
5
|
-
|
6
|
-
gem install -l rails_currency-1.0.gem
|
7
|
-
|
8
|
-
== Usage
|
9
|
-
|
10
|
-
{{{
|
11
|
-
require "rails_currency"
|
12
|
-
result = RailsCurrency::Convertor.convert(100, "CNY", "USD")
|
13
|
-
}}}
|
14
|
-
|
15
|
-
== Available Currency List
|
16
|
-
|
17
|
-
{{{
|
18
|
-
AFN 'Afghanistan Afghanis'
|
19
|
-
ALL 'Albania Leke'
|
20
|
-
DZD 'Algeria Dinars'
|
21
|
-
ARS 'Argentina Pesos'
|
22
|
-
AUS 'Australia Dollars'
|
23
|
-
BSD 'Bahamas Dollars'
|
24
|
-
BHD 'Bahrain Dinars'
|
25
|
-
BDT 'Bangladesh Taka'
|
26
|
-
BBD 'Barbados Dollars'
|
27
|
-
BMD 'Bermuda Dollars'
|
28
|
-
BRL 'Brazil Reais'
|
29
|
-
BGN 'Bulgaria Leva'
|
30
|
-
XOF 'CFA BCEAO Francs'
|
31
|
-
XAF 'CFA BEAC Francs'
|
32
|
-
CAD 'Canada Dollars'
|
33
|
-
CLP 'Chile Pesos'
|
34
|
-
CNY 'China Yuan Renminbi'
|
35
|
-
COP 'Colombia Pesos'
|
36
|
-
XPF 'Comptoirs Français du Pacifique Francs'
|
37
|
-
CRC 'Costa Rica Colones'
|
38
|
-
HRK 'Croatia Kuna'
|
39
|
-
CZK 'Czech Republic Koruny'
|
40
|
-
DKK 'Denmark Kroner'
|
41
|
-
DOP 'Dominican Republic Pesos'
|
42
|
-
XCD 'East Caribbean Dollars'
|
43
|
-
EGP 'Egypt Pounds'
|
44
|
-
EEK 'Estonia Krooni'
|
45
|
-
EUR 'Euro'
|
46
|
-
FJD 'Fiji Dollars'
|
47
|
-
XAU 'Gold Ounces'
|
48
|
-
HKD 'Hong Kong Dollars'
|
49
|
-
HUF 'Hungary Forint'
|
50
|
-
XDR 'IMF Special Drawing Rights'
|
51
|
-
ISK 'Iceland Kronur'
|
52
|
-
INR 'India Rupees'
|
53
|
-
IDR 'Indonesia Rupiahs'
|
54
|
-
IRR 'Iran Rials'
|
55
|
-
IQD 'Iraq Dinars'
|
56
|
-
ILS 'Israel New Shekels'
|
57
|
-
JMD 'Jamaica Dollars'
|
58
|
-
JPY 'Japan Yen'
|
59
|
-
JOD 'Jordan Dinars'
|
60
|
-
KES 'Kenya Shillings'
|
61
|
-
KWD 'Kuwait Dinars'
|
62
|
-
LBP 'Lebanon Pounds'
|
63
|
-
MYR 'Malaysia Ringgits'
|
64
|
-
MUR 'Mauritius Rupees'
|
65
|
-
MXN 'Mexico Pesos'
|
66
|
-
MAD 'Morocco Dirhams'
|
67
|
-
NZD 'New Zealand Dollars'
|
68
|
-
NOK 'Norway Kroner'
|
69
|
-
OMR 'Oman Rials'
|
70
|
-
PKR 'Pakistan Rupees'
|
71
|
-
XPD 'Palladium Ounces'
|
72
|
-
PEN 'Peru Nuevos Soles'
|
73
|
-
PHP 'Philippines Pesos'
|
74
|
-
XPT 'Platinum Ounces'
|
75
|
-
PLN 'Poland Zlotych'
|
76
|
-
QAR 'Qatar Riyals'
|
77
|
-
RON 'Romania New Lei'
|
78
|
-
RUB 'Russia Rubles'
|
79
|
-
SAR 'Saudi Arabia Riyals'
|
80
|
-
XAG 'Silver Ounces'
|
81
|
-
SGD 'Singapore Dollars'
|
82
|
-
SKK 'Slovakia Koruny'
|
83
|
-
ZAR 'South Africa Rand'
|
84
|
-
KRW 'South Korea Won'
|
85
|
-
LKR 'Sri Lanka Rupees'
|
86
|
-
SDG 'Sudan Pounds'
|
87
|
-
SEK 'Sweden Kronor'
|
88
|
-
CHF 'Switzerland Francs'
|
89
|
-
TWD 'Taiwan New Dollars'
|
90
|
-
THB 'Thailand Baht'
|
91
|
-
TTD 'Trinidad and Tobago Dollars'
|
92
|
-
TND 'Tunisia Dinars'
|
93
|
-
TRY 'Turkey New Lira'
|
94
|
-
AED 'United Arab Emirates Dirhams'
|
95
|
-
GBP 'United Kingdom Pounds'
|
96
|
-
USD 'United States Dollars'
|
97
|
-
VEF 'Venezuela Bolivares Fuertes'
|
98
|
-
VND 'Vietnam Dong'
|
99
|
-
}}}
|
100
|
-
|
101
|
-
== LICENSE
|
102
|
-
|
103
|
-
(The MIT License)
|
104
|
-
|
105
|
-
Copyright (c) 2008 Naveen Joshi
|
106
|
-
|
107
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
108
|
-
a copy of this software and associated documentation files (the
|
109
|
-
'Software'), to deal in the Software without restriction, including
|
110
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
111
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
112
|
-
permit persons to whom the Software is furnished to do so, subject to
|
113
|
-
the following conditions:
|
114
|
-
|
115
|
-
The above copyright notice and this permission notice shall be
|
116
|
-
included in all copies or substantial portions of the Software.
|
117
|
-
|
118
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
119
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
120
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
121
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
122
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
123
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
124
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -1,91 +0,0 @@
|
|
1
|
-
module RailsCurrency
|
2
|
-
module Constants
|
3
|
-
CurrencyUrl = "http://www.xe.com/ucc/convert.cgi"
|
4
|
-
Params = {"User-Agent"=>"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9", "Connection"=>"Keep-Alive", "Keep-Alive"=>"30"}
|
5
|
-
|
6
|
-
CurrencyList = {
|
7
|
-
:AFN => 'Afghanistan Afghanis',
|
8
|
-
:ALL => 'Albania Leke',
|
9
|
-
:DZD => 'Algeria Dinars',
|
10
|
-
:ARS => 'Argentina Pesos',
|
11
|
-
:AUS => 'Australia Dollars',
|
12
|
-
:BSD => 'Bahamas Dollars',
|
13
|
-
:BHD => 'Bahrain Dinars',
|
14
|
-
:BDT => 'Bangladesh Taka',
|
15
|
-
:BBD => 'Barbados Dollars',
|
16
|
-
:BMD => 'Bermuda Dollars',
|
17
|
-
:BRL => 'Brazil Reais',
|
18
|
-
:BGN => 'Bulgaria Leva',
|
19
|
-
:XOF => 'CFA BCEAO Francs',
|
20
|
-
:XAF => 'CFA BEAC Francs',
|
21
|
-
:CAD => 'Canada Dollars',
|
22
|
-
:CLP => 'Chile Pesos',
|
23
|
-
:CNY => 'China Yuan Renminbi',
|
24
|
-
:COP => 'Colombia Pesos',
|
25
|
-
:XPF => 'Comptoirs Français du Pacifique Francs',
|
26
|
-
:CRC => 'Costa Rica Colones',
|
27
|
-
:HRK => 'Croatia Kuna',
|
28
|
-
:CZK => 'Czech Republic Koruny',
|
29
|
-
:DKK => 'Denmark Kroner',
|
30
|
-
:DOP => 'Dominican Republic Pesos',
|
31
|
-
:XCD => 'East Caribbean Dollars',
|
32
|
-
:EGP => 'Egypt Pounds',
|
33
|
-
:EEK => 'Estonia Krooni',
|
34
|
-
:EUR => 'Euro',
|
35
|
-
:FJD => 'Fiji Dollars',
|
36
|
-
:XAU => 'Gold Ounces',
|
37
|
-
:HKD => 'Hong Kong Dollars',
|
38
|
-
:HUF => 'Hungary Forint',
|
39
|
-
:XDR => 'IMF Special Drawing Rights',
|
40
|
-
:ISK => 'Iceland Kronur',
|
41
|
-
:INR => 'India Rupees',
|
42
|
-
:IDR => 'Indonesia Rupiahs',
|
43
|
-
:IRR => 'Iran Rials',
|
44
|
-
:IQD => 'Iraq Dinars',
|
45
|
-
:ILS => 'Israel New Shekels',
|
46
|
-
:JMD => 'Jamaica Dollars',
|
47
|
-
:JPY => 'Japan Yen',
|
48
|
-
:JOD => 'Jordan Dinars',
|
49
|
-
:KES => 'Kenya Shillings',
|
50
|
-
:KWD => 'Kuwait Dinars',
|
51
|
-
:LBP => 'Lebanon Pounds',
|
52
|
-
:MYR => 'Malaysia Ringgits',
|
53
|
-
:MUR => 'Mauritius Rupees',
|
54
|
-
:MXN => 'Mexico Pesos',
|
55
|
-
:MAD => 'Morocco Dirhams',
|
56
|
-
:NZD => 'New Zealand Dollars',
|
57
|
-
:NOK => 'Norway Kroner',
|
58
|
-
:OMR => 'Oman Rials',
|
59
|
-
:PKR => 'Pakistan Rupees',
|
60
|
-
:XPD => 'Palladium Ounces',
|
61
|
-
:PEN => 'Peru Nuevos Soles',
|
62
|
-
:PHP => 'Philippines Pesos',
|
63
|
-
:XPT => 'Platinum Ounces',
|
64
|
-
:PLN => 'Poland Zlotych',
|
65
|
-
:QAR => 'Qatar Riyals',
|
66
|
-
:RON => 'Romania New Lei',
|
67
|
-
:RUB => 'Russia Rubles',
|
68
|
-
:SAR => 'Saudi Arabia Riyals',
|
69
|
-
:XAG => 'Silver Ounces',
|
70
|
-
:SGD => 'Singapore Dollars',
|
71
|
-
:SKK => 'Slovakia Koruny',
|
72
|
-
:ZAR => 'South Africa Rand',
|
73
|
-
:KRW => 'South Korea Won',
|
74
|
-
:LKR => 'Sri Lanka Rupees',
|
75
|
-
:SDG => 'Sudan Pounds',
|
76
|
-
:SEK => 'Sweden Kronor',
|
77
|
-
:CHF => 'Switzerland Francs',
|
78
|
-
:TWD => 'Taiwan New Dollars',
|
79
|
-
:THB => 'Thailand Baht',
|
80
|
-
:TTD => 'Trinidad and Tobago Dollars',
|
81
|
-
:TND => 'Tunisia Dinars',
|
82
|
-
:TRY => 'Turkey New Lira',
|
83
|
-
:AED => 'United Arab Emirates Dirhams',
|
84
|
-
:GBP => 'United Kingdom Pounds',
|
85
|
-
:USD => 'United States Dollars',
|
86
|
-
:VEF => 'Venezuela Bolivares Fuertes',
|
87
|
-
:VND => 'Vietnam Dong',
|
88
|
-
:ZMK => 'Zambia Kwacha'
|
89
|
-
}
|
90
|
-
end
|
91
|
-
end
|
data/test/ts_convertor.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
$:.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")
|
2
|
-
|
3
|
-
require 'test/unit'
|
4
|
-
require 'rails_currency'
|
5
|
-
|
6
|
-
class RCurrencyTest < Test::Unit::TestCase
|
7
|
-
def test_convert
|
8
|
-
assert_kind_of Numeric, RailsCurrency::Convertor.convert(100, "CNY", "USD")
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_invalid_convert
|
12
|
-
assert_raise RailsCurrency::InvalidAmountError do
|
13
|
-
RailsCurrency::Convertor.convert("100", "CNY", "USD")
|
14
|
-
end
|
15
|
-
|
16
|
-
assert_raise RailsCurrency::UnknownCurrencyError do
|
17
|
-
RailsCurrency::Convertor.convert(100, "CNY", "ABC")
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|