google_currency_convert 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/curr_code.csv ADDED
@@ -0,0 +1,168 @@
1
+ AED United Arab Emirates Dirham (AED)
2
+ AFN Afghan Afghani (AFN)
3
+ ALL Albanian Lek (ALL)
4
+ AMD Armenian Dram (AMD)
5
+ ANG Netherlands Antillean Guilder (ANG)
6
+ AOA Angolan Kwanza (AOA)
7
+ ARS Argentine Peso (ARS)
8
+ AUD Australian Dollar (A$)
9
+ AWG Aruban Florin (AWG)
10
+ AZN Azerbaijani Manat (AZN)
11
+ BAM Bosnia-Herzegovina Convertible Mark (BAM)
12
+ BBD Barbadian Dollar (BBD)
13
+ BDT Bangladeshi Taka (BDT)
14
+ BGN Bulgarian Lev (BGN)
15
+ BHD Bahraini Dinar (BHD)
16
+ BIF Burundian Franc (BIF)
17
+ BMD Bermudan Dollar (BMD)
18
+ BND Brunei Dollar (BND)
19
+ BOB Bolivian Boliviano (BOB)
20
+ BRL Brazilian Real (R$)
21
+ BSD Bahamian Dollar (BSD)
22
+ BTC Bitcoin (฿)
23
+ BTN Bhutanese Ngultrum (BTN)
24
+ BWP Botswanan Pula (BWP)
25
+ BYR Belarusian Ruble (BYR)
26
+ BZD Belize Dollar (BZD)
27
+ CAD Canadian Dollar (CA$)
28
+ CDF Congolese Franc (CDF)
29
+ CHF Swiss Franc (CHF)
30
+ CLF Chilean Unit of Account (UF) (CLF)
31
+ CLP Chilean Peso (CLP)
32
+ CNH CNH (CNH)
33
+ CNY Chinese Yuan (CN¥)
34
+ COP Colombian Peso (COP)
35
+ CRC Costa Rican Colón (CRC)
36
+ CUP Cuban Peso (CUP)
37
+ CVE Cape Verdean Escudo (CVE)
38
+ CZK Czech Republic Koruna (CZK)
39
+ DEM German Mark (DEM)
40
+ DJF Djiboutian Franc (DJF)
41
+ DKK Danish Krone (DKK)
42
+ DOP Dominican Peso (DOP)
43
+ DZD Algerian Dinar (DZD)
44
+ EGP Egyptian Pound (EGP)
45
+ ERN Eritrean Nakfa (ERN)
46
+ ETB Ethiopian Birr (ETB)
47
+ EUR Euro (€)
48
+ FIM Finnish Markka (FIM)
49
+ FJD Fijian Dollar (FJD)
50
+ FKP Falkland Islands Pound (FKP)
51
+ FRF French Franc (FRF)
52
+ GBP British Pound (£)
53
+ GEL Georgian Lari (GEL)
54
+ GHS Ghanaian Cedi (GHS)
55
+ GIP Gibraltar Pound (GIP)
56
+ GMD Gambian Dalasi (GMD)
57
+ GNF Guinean Franc (GNF)
58
+ GTQ Guatemalan Quetzal (GTQ)
59
+ GYD Guyanaese Dollar (GYD)
60
+ HKD Hong Kong Dollar (HK$)
61
+ HNL Honduran Lempira (HNL)
62
+ HRK Croatian Kuna (HRK)
63
+ HTG Haitian Gourde (HTG)
64
+ HUF Hungarian Forint (HUF)
65
+ IDR Indonesian Rupiah (IDR)
66
+ IEP Irish Pound (IEP)
67
+ ILS Israeli New Sheqel (₪)
68
+ INR Indian Rupee (Rs.)
69
+ IQD Iraqi Dinar (IQD)
70
+ IRR Iranian Rial (IRR)
71
+ ISK Icelandic Króna (ISK)
72
+ ITL Italian Lira (ITL)
73
+ JMD Jamaican Dollar (JMD)
74
+ JOD Jordanian Dinar (JOD)
75
+ JPY Japanese Yen (¥)
76
+ KES Kenyan Shilling (KES)
77
+ KGS Kyrgystani Som (KGS)
78
+ KHR Cambodian Riel (KHR)
79
+ KMF Comorian Franc (KMF)
80
+ KPW North Korean Won (KPW)
81
+ KRW South Korean Won (₩)
82
+ KWD Kuwaiti Dinar (KWD)
83
+ KYD Cayman Islands Dollar (KYD)
84
+ KZT Kazakhstani Tenge (KZT)
85
+ LAK Laotian Kip (LAK)
86
+ LBP Lebanese Pound (LBP)
87
+ LKR Sri Lankan Rupee (LKR)
88
+ LRD Liberian Dollar (LRD)
89
+ LSL Lesotho Loti (LSL)
90
+ LTL Lithuanian Litas (LTL)
91
+ LVL Latvian Lats (LVL)
92
+ LYD Libyan Dinar (LYD)
93
+ MAD Moroccan Dirham (MAD)
94
+ MDL Moldovan Leu (MDL)
95
+ MGA Malagasy Ariary (MGA)
96
+ MKD Macedonian Denar (MKD)
97
+ MMK Myanmar Kyat (MMK)
98
+ MNT Mongolian Tugrik (MNT)
99
+ MOP Macanese Pataca (MOP)
100
+ MRO Mauritanian Ouguiya (MRO)
101
+ MUR Mauritian Rupee (MUR)
102
+ MVR Maldivian Rufiyaa (MVR)
103
+ MWK Malawian Kwacha (MWK)
104
+ MXN Mexican Peso (MX$)
105
+ MYR Malaysian Ringgit (MYR)
106
+ MZN Mozambican Metical (MZN)
107
+ NAD Namibian Dollar (NAD)
108
+ NGN Nigerian Naira (NGN)
109
+ NIO Nicaraguan Córdoba (NIO)
110
+ NOK Norwegian Krone (NOK)
111
+ NPR Nepalese Rupee (NPR)
112
+ NZD New Zealand Dollar (NZ$)
113
+ OMR Omani Rial (OMR)
114
+ PAB Panamanian Balboa (PAB)
115
+ PEN Peruvian Nuevo Sol (PEN)
116
+ PGK Papua New Guinean Kina (PGK)
117
+ PHP Philippine Peso (Php)
118
+ PKG PKG (PKG)
119
+ PKR Pakistani Rupee (PKR)
120
+ PLN Polish Zloty (PLN)
121
+ PYG Paraguayan Guarani (PYG)
122
+ QAR Qatari Rial (QAR)
123
+ RON Romanian Leu (RON)
124
+ RSD Serbian Dinar (RSD)
125
+ RUB Russian Ruble (RUB)
126
+ RWF Rwandan Franc (RWF)
127
+ SAR Saudi Riyal (SAR)
128
+ SBD Solomon Islands Dollar (SBD)
129
+ SCR Seychellois Rupee (SCR)
130
+ SDG Sudanese Pound (SDG)
131
+ SEK Swedish Krona (SEK)
132
+ SGD Singapore Dollar (SGD)
133
+ SHP St. Helena Pound (SHP)
134
+ SLL Sierra Leonean Leone (SLL)
135
+ SOS Somali Shilling (SOS)
136
+ SRD Surinamese Dollar (SRD)
137
+ STD São Tomé Príncipe Dobra (STD)
138
+ SVC Salvadoran Colón (SVC)
139
+ SYP Syrian Pound (SYP)
140
+ SZL Swazi Lilangeni (SZL)
141
+ THB Thai Baht (THB)
142
+ TJS Tajikistani Somoni (TJS)
143
+ TMT Turkmenistani Manat (TMT)
144
+ TND Tunisian Dinar (TND)
145
+ TOP Tongan Paʻanga (TOP)
146
+ TRY Turkish Lira (TRY)
147
+ TTD Trinidad Tobago Dollar (TTD)
148
+ TWD New Taiwan Dollar (NT$)
149
+ TZS Tanzanian Shilling (TZS)
150
+ UAH Ukrainian Hryvnia (UAH)
151
+ UGX Ugandan Shilling (UGX)
152
+ USD US Dollar ($)
153
+ UYU Uruguayan Peso (UYU)
154
+ UZS Uzbekistani Som (UZS)
155
+ VEF Venezuelan Bolívar (VEF)
156
+ VND Vietnamese Dong (₫)
157
+ VUV Vanuatu Vatu (VUV)
158
+ WST Samoan Tala (WST)
159
+ XAF Central African CFA Franc (FCFA)
160
+ XCD East Caribbean Dollar (EC$)
161
+ XDR Special Drawing Rights (XDR)
162
+ XOF West African CFA Franc (CFA)
163
+ XPF CFP Franc (CFPF)
164
+ YER Yemeni Rial (YER)
165
+ ZAR South African Rand (ZAR)
166
+ ZMK Zambian Kwacha (1968–2012) (ZMK)
167
+ ZMW Zambian Kwacha (ZMW)
168
+ ZWL Zimbabwean Dollar (2009) (ZWL)
@@ -0,0 +1,37 @@
1
+ require 'net/http'
2
+ require 'nokogiri'
3
+
4
+ class GoogleCurrencyConvert
5
+
6
+ def self.currency_info
7
+ unless @info
8
+ @info = []
9
+ file_path = File.expand_path("curr_code.csv", File.dirname(__FILE__))
10
+ IO.readlines(file_path).each { |line| @info << line.strip }
11
+ end
12
+ @info
13
+ end
14
+
15
+ def self.currency_codes
16
+ @info ||= currency_info
17
+ @info.map { |i| i.split(' ')[0] }
18
+ end
19
+
20
+ def self.currency_convert(from, to, amount)
21
+ if not currency_codes.include?(from) or not currency_codes.include?(to)
22
+ return "Error: cannot support such currency code"
23
+ end
24
+
25
+ return "Error: amount must be a positive integer" if amount <= 0 or amount.class != Fixnum
26
+
27
+ host = "www.google.com"
28
+ http = Net::HTTP.new(host, 80)
29
+ url = "/finance/converter?a=#{amount}&from=#{from}&to=#{to}"
30
+ response = http.get(url)
31
+
32
+ doc = Nokogiri::HTML(response.body)
33
+ result = doc.css('div#currency_converter_result').first.text
34
+ result.split(' ')[3].to_f
35
+ end
36
+
37
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: google_currency_convert
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - liuxingqi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-07-09 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Google currency convert by google finance API
15
+ email: lxq_102172@163.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/google_currency_convert.rb
21
+ - lib/curr_code.csv
22
+ homepage: http://rubygems.org/gems/google_currency_convert
23
+ licenses:
24
+ - MIT
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 1.8.23
44
+ signing_key:
45
+ specification_version: 3
46
+ summary: Google currency convert
47
+ test_files: []