EGP_Rates 0.3.0 → 1.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 +4 -4
- data/lib/egp_rates/aaib.rb +0 -18
- data/lib/egp_rates/adib.rb +53 -0
- data/lib/egp_rates/al_ahli_bank_of_kuwait.rb +0 -2
- data/lib/egp_rates/al_baraka_bank.rb +0 -18
- data/lib/egp_rates/alex_bank.rb +54 -0
- data/lib/egp_rates/bank.rb +31 -0
- data/lib/egp_rates/banque_du_caire.rb +0 -28
- data/lib/egp_rates/banque_misr.rb +2 -2
- data/lib/egp_rates/blom.rb +57 -0
- data/lib/egp_rates/cae.rb +0 -2
- data/lib/egp_rates/cbe.rb +0 -20
- data/lib/egp_rates/edbe.rb +56 -0
- data/lib/egp_rates/egb.rb +56 -0
- data/lib/egp_rates/faisal_bank.rb +55 -0
- data/lib/egp_rates/midb.rb +0 -2
- data/lib/egp_rates/nbg.rb +55 -0
- data/lib/egp_rates/saib.rb +0 -2
- data/lib/egp_rates/suez_canal_bank.rb +0 -23
- data/lib/egp_rates/ube.rb +0 -2
- data/lib/egp_rates.rb +60 -0
- data/spec/cassettes/ADIB.yml +457 -0
- data/spec/cassettes/AlexBank.yml +972 -0
- data/spec/cassettes/Blom.yml +868 -0
- data/spec/cassettes/EDBE.yml +69 -0
- data/spec/cassettes/EGB.yml +366 -0
- data/spec/cassettes/FaisalBank.yml +445 -0
- data/spec/cassettes/NBG.yml +760 -0
- data/spec/egp_rates/adib_spec.rb +75 -0
- data/spec/egp_rates/alex_bank_spec.rb +112 -0
- data/spec/egp_rates/banque_misr_spec.rb +4 -4
- data/spec/egp_rates/blom_spec.rb +88 -0
- data/spec/egp_rates/edbe_spec.rb +69 -0
- data/spec/egp_rates/egb_spec.rb +93 -0
- data/spec/egp_rates/faisal_bank_spec.rb +86 -0
- data/spec/egp_rates/nbg_spec.rb +77 -0
- data/spec/egp_rates_spec.rb +80 -2
- metadata +23 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e74254f42514b07497208b56180428b55ee1207c
|
4
|
+
data.tar.gz: 56de3e0b1021260b15d3046c563e339669ca672c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62fb9d7476d250e3681ad735db2c0b11cb5b4a594d6c7c889717fa9f4b05670bf5af53cbbbf81ffae26309f3ceca6bc4eb7f03221ab8c87fac556f257ddf3858
|
7
|
+
data.tar.gz: fb3f12ce1ebdc53eb5700e71b51766ba08491c7e5b46a1549b2c85d9d9f38ec00dc6d5c696f6a45cbcde496d2f9ffcf03d4e4ddffb8fb13162e1d8cb26a8c383
|
data/lib/egp_rates/aaib.rb
CHANGED
@@ -48,24 +48,6 @@ module EGPRates
|
|
48
48
|
table_rows.lazy.map(&:children).map { |cell| cell.map(&:text) }
|
49
49
|
end
|
50
50
|
|
51
|
-
# Convert currency string to ISO symbol
|
52
|
-
# @param currency [String] "US Dollar"
|
53
|
-
# @return [Symbol] :USD ISO currency name
|
54
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
55
|
-
def currency_symbol(currency)
|
56
|
-
case currency
|
57
|
-
when /US DOLLAR/ then :USD
|
58
|
-
when /EURO/ then :EUR
|
59
|
-
when /STERLING/ then :GBP
|
60
|
-
when /SWISS/ then :CHF
|
61
|
-
when /SAUDI/ then :SAR
|
62
|
-
when /KUWAITI/ then :KWD
|
63
|
-
when /DIRHAM/ then :AED
|
64
|
-
else fail ResponseError, "Unknown currency #{currency}"
|
65
|
-
end
|
66
|
-
end
|
67
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
68
|
-
|
69
51
|
# Parse the #raw_exchange_rates returned in response
|
70
52
|
# @param [Array] of the raw_data scraped
|
71
53
|
# @return [Hash] of exchange rates for selling and buying
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module EGPRates
|
3
|
+
# Abu Dhabi Islamic Bank (ADIB)
|
4
|
+
class ADIB < EGPRates::Bank
|
5
|
+
def initialize
|
6
|
+
@sym = :ADIB
|
7
|
+
@uri = URI.parse('https://www.adib.eg/')
|
8
|
+
end
|
9
|
+
|
10
|
+
# @return [Hash] of exchange rates for selling and buying
|
11
|
+
# {
|
12
|
+
# { sell: { SYM: rate }, { SYM: rate }, ... },
|
13
|
+
# { buy: { SYM: rate }, { SYM: rate }, ... }
|
14
|
+
# }
|
15
|
+
def exchange_rates
|
16
|
+
@exchange_rates ||= parse(raw_exchange_rates)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
# Send the request to the URL and retrun raw data of the response
|
22
|
+
# @return [Enumerator::Lazy] with the table row in HTML that evaluates to
|
23
|
+
# [
|
24
|
+
# ["\n", "USD", "\n", "17.0000", "\n", "17.5000", "\n"],
|
25
|
+
# ["\n", "GBP", "\n", "20.9049", "\n", "21.7630", "\n"],
|
26
|
+
# ...
|
27
|
+
# ]
|
28
|
+
def raw_exchange_rates
|
29
|
+
table_rows = Oga.parse_html(response.body).css('.CallUs tbody tr')
|
30
|
+
# ADIB porvide 5 currencies on the home page (and 4 rows of info)
|
31
|
+
fail ResponseError, 'Unknown HTML' unless table_rows&.size == 9
|
32
|
+
table_rows.lazy.drop(4).map(&:children).map { |cell| cell.map(&:text) }
|
33
|
+
end
|
34
|
+
|
35
|
+
# Parse the #raw_exchange_rates returned in response
|
36
|
+
# @param [Array] of the raw_data scraped
|
37
|
+
# @return [Hash] of exchange rates for selling and buying
|
38
|
+
# {
|
39
|
+
# { sell: { SYM: rate }, { SYM: rate }, ... },
|
40
|
+
# { buy: { SYM: rate }, { SYM: rate }, ... }
|
41
|
+
# }
|
42
|
+
def parse(raw_data)
|
43
|
+
raw_data.each_with_object(sell: {}, buy: {}) do |row, result|
|
44
|
+
sell_rate = row[5].to_f
|
45
|
+
buy_rate = row[3].to_f
|
46
|
+
currency = row[1].to_sym
|
47
|
+
|
48
|
+
result[:sell][currency] = sell_rate
|
49
|
+
result[:buy][currency] = buy_rate
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -30,8 +30,6 @@ module EGPRates
|
|
30
30
|
# ]
|
31
31
|
#
|
32
32
|
def raw_exchange_rates
|
33
|
-
response = Net::HTTP.get_response(@uri)
|
34
|
-
fail ResponseError, response.code unless response.is_a? Net::HTTPSuccess
|
35
33
|
table_rows = Oga.parse_html(response.body).css('.ORANGE_TEXT, .BLUE_TEXT')
|
36
34
|
# AlAhliBankOfKuwait porvide 8 currencies on the home page
|
37
35
|
fail ResponseError, 'Unknown HTML' unless table_rows&.size == 8
|
@@ -38,24 +38,6 @@ module EGPRates
|
|
38
38
|
table_rows.lazy.drop(1).map(&:children).map { |cell| cell.map(&:text) }
|
39
39
|
end
|
40
40
|
|
41
|
-
# Convert currency string to ISO symbol
|
42
|
-
# @param currency [String] "US Dollar"
|
43
|
-
# @return [Symbol] :USD ISO currency name
|
44
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
45
|
-
def currency_symbol(currency)
|
46
|
-
case currency
|
47
|
-
when /USD/ then :USD
|
48
|
-
when /EURO/ then :EUR
|
49
|
-
when /GBP/ then :GBP
|
50
|
-
when /CHF/ then :CHF
|
51
|
-
when /JPY/ then :JPY
|
52
|
-
when /SAR/ then :SAR
|
53
|
-
when /BHD/ then :BHD
|
54
|
-
else fail ResponseError, "Unknown currency #{currency}"
|
55
|
-
end
|
56
|
-
end
|
57
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
58
|
-
|
59
41
|
# Parse the #raw_exchange_rates returned in response
|
60
42
|
# @param [Array] of the raw_data scraped
|
61
43
|
# [
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module EGPRates
|
3
|
+
# Bank of Alexandria
|
4
|
+
class AlexBank < EGPRates::Bank
|
5
|
+
def initialize
|
6
|
+
@sym = :AlexBank
|
7
|
+
@uri = URI.parse('https://www.alexbank.com/En/Home/ExchangeRates')
|
8
|
+
end
|
9
|
+
|
10
|
+
# @return [Hash] of exchange rates for selling and buying
|
11
|
+
# {
|
12
|
+
# { sell: { SYM: rate }, { SYM: rate }, ... },
|
13
|
+
# { buy: { SYM: rate }, { SYM: rate }, ... }
|
14
|
+
# }
|
15
|
+
def exchange_rates
|
16
|
+
@exchange_rates ||= parse(raw_exchange_rates)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
# Send the request to the URL and retrun raw data of the response
|
22
|
+
# @return [Enumerator::Lazy] with the table row in HTML that evaluates to
|
23
|
+
# ["", "US Dollar", "", ..., "17.10000", "", "17.50000", ""]
|
24
|
+
# ["", "British Pound", "", ..., "21.12363", "", "21.60025", ""]
|
25
|
+
# ...
|
26
|
+
#
|
27
|
+
def raw_exchange_rates
|
28
|
+
# AlexBank provide 17 currencies (and 1 <th>)
|
29
|
+
table_rows = Oga.parse_html(response.body).css('.exchangerate-table tr')
|
30
|
+
fail ResponseError, 'Unknown HTML' unless table_rows&.size == 18
|
31
|
+
table_rows.lazy.drop(1).map(&:children).map do |cell|
|
32
|
+
cell.map(&:text).map(&:strip)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Parse the #raw_exchange_rates returned in response
|
37
|
+
# @param [Array] of the raw_data scraped
|
38
|
+
# @return [Hash] of exchange rates for selling and buying
|
39
|
+
# {
|
40
|
+
# { sell: { SYM: rate }, { SYM: rate }, ... },
|
41
|
+
# { buy: { SYM: rate }, { SYM: rate }, ... }
|
42
|
+
# }
|
43
|
+
def parse(raw_data)
|
44
|
+
raw_data.each_with_object(sell: {}, buy: {}) do |row, result|
|
45
|
+
sell_rate = row[9].to_f
|
46
|
+
buy_rate = row[7].to_f
|
47
|
+
currency = currency_symbol(row[1])
|
48
|
+
|
49
|
+
result[:sell][currency] = sell_rate
|
50
|
+
result[:buy][currency] = buy_rate
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/egp_rates/bank.rb
CHANGED
@@ -23,6 +23,37 @@ module EGPRates
|
|
23
23
|
response
|
24
24
|
end
|
25
25
|
|
26
|
+
# Convert currency string to ISO symbol
|
27
|
+
# @param currency [String] "US Dollar"
|
28
|
+
# @return [Symbol] :USD ISO currency name
|
29
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
30
|
+
# rubocop:disable Metrics/MethodLength
|
31
|
+
def currency_symbol(currency)
|
32
|
+
case currency
|
33
|
+
when /UAE|EMIRATES|Dirham/i then :AED
|
34
|
+
when /Australian/i then :AUD
|
35
|
+
when /Bahrain|BHD/i then :BHD
|
36
|
+
when /Canadian/i then :CAD
|
37
|
+
when /Swiss|CHF/i then :CHF
|
38
|
+
when /Chinese/ then :CNY
|
39
|
+
when /Danish/i then :DKK
|
40
|
+
when /Euro|EUR/i then :EUR
|
41
|
+
when /British|Sterling|GBP/i then :GBP
|
42
|
+
when /Jordanian/i then :JOD
|
43
|
+
when /Japanese|JPY|YEN/i then :JPY
|
44
|
+
when /Kuwait/i then :KWD
|
45
|
+
when /Norwegian/i then :NOK
|
46
|
+
when /Omani/i then :OMR
|
47
|
+
when /Qatar/i then :QAR
|
48
|
+
when /SAR|Saudi/i then :SAR
|
49
|
+
when /Swidish|Swedish/i then :SEK
|
50
|
+
when /US Dollar|USD/i then :USD
|
51
|
+
else fail ResponseError, "Unknown currency #{currency}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
55
|
+
# rubocop:enable Metrics/MethodLength
|
56
|
+
|
26
57
|
# Parse the #raw_exchange_rates returned in response
|
27
58
|
# @param [Array] of the raw_data scraped
|
28
59
|
# [
|
@@ -34,33 +34,5 @@ module EGPRates
|
|
34
34
|
fail ResponseError, 'Unknown HTML' unless table_rows&.size == 19
|
35
35
|
table_rows.lazy.drop(2).map(&:children).map { |cell| cell.map(&:text) }
|
36
36
|
end
|
37
|
-
|
38
|
-
# Convert currency string to ISO symbol
|
39
|
-
# @param currency [String] "US Dollar"
|
40
|
-
# @return [Symbol] :USD ISO currency name
|
41
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
42
|
-
def currency_symbol(currency)
|
43
|
-
case currency
|
44
|
-
when /EMIRATES/ then :AED
|
45
|
-
when /AUSTRALIAN/ then :AUD
|
46
|
-
when /BAHRAIN/ then :BHD
|
47
|
-
when /CANADIAN/ then :CAD
|
48
|
-
when /SWISS/ then :CHF
|
49
|
-
when /DANISH/ then :DKK
|
50
|
-
when /EURO/ then :EUR
|
51
|
-
when /BRITISH/ then :GBP
|
52
|
-
when /JORDANIAN/ then :JOD
|
53
|
-
when /JAPANESE/ then :JPY
|
54
|
-
when /KUWAITI/ then :KWD
|
55
|
-
when /NORWEGIAN/ then :NOK
|
56
|
-
when /OMANI/ then :OMR
|
57
|
-
when /QATAR/ then :QAR
|
58
|
-
when /SAUDI/ then :SAR
|
59
|
-
when /SWEDISH/ then :SEK
|
60
|
-
when /US DOLLAR/ then :USD
|
61
|
-
else fail ResponseError, "Unknown currency #{currency}"
|
62
|
-
end
|
63
|
-
end
|
64
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
65
37
|
end
|
66
38
|
end
|
@@ -48,7 +48,7 @@ module EGPRates
|
|
48
48
|
when /AUSTRALIA/ then :AUD
|
49
49
|
when /BAHRAIN/ then :BHD
|
50
50
|
when /CANADA/ then :CAD
|
51
|
-
when /
|
51
|
+
when /SWISS/ then :CHF
|
52
52
|
when /DENMARK/ then :DKK
|
53
53
|
when /EURO/ then :EUR
|
54
54
|
when /GB POUND/ then :GBP
|
@@ -59,7 +59,7 @@ module EGPRates
|
|
59
59
|
when /OMAN/ then :OMR
|
60
60
|
when /QATARI/ then :QAR
|
61
61
|
when /SAUDI/ then :SAR
|
62
|
-
when /
|
62
|
+
when /SWEDISH/ then :SEK
|
63
63
|
when /US DOLLAR/ then :USD
|
64
64
|
else fail ResponseError, "Unknown currency #{currency}"
|
65
65
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module EGPRates
|
3
|
+
# Blom Bank Egypt
|
4
|
+
class Blom < EGPRates::Bank
|
5
|
+
def initialize
|
6
|
+
@sym = :Blom
|
7
|
+
@uri = URI.parse('http://www.blombankegypt.com/BlomEgypt/Exchange-rates')
|
8
|
+
end
|
9
|
+
|
10
|
+
# @return [Hash] of exchange rates for selling and buying
|
11
|
+
# {
|
12
|
+
# { sell: { SYM: rate }, { SYM: rate }, ... },
|
13
|
+
# { buy: { SYM: rate }, { SYM: rate }, ... }
|
14
|
+
# }
|
15
|
+
def exchange_rates
|
16
|
+
@exchange_rates ||= parse(raw_exchange_rates)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
# Send the request to the URL and retrun raw data of the response
|
22
|
+
# @return [Enumerator::Lazy] with the table row in HTML that evaluates to
|
23
|
+
# [
|
24
|
+
# ["", "USD 02", "", "", "", ..., "17.0000", "", "17.7500", ""]
|
25
|
+
# ["", "EURO 30", "", "", "", ..., "17.9690", "", "18.8896", ""]
|
26
|
+
# ...
|
27
|
+
# ]
|
28
|
+
def raw_exchange_rates
|
29
|
+
table_rows = Oga.parse_html(response.body).css('.tableHolder').first
|
30
|
+
table_rows = table_rows&.css('tr')
|
31
|
+
# Blom porvide 14 currencies on the home page (and 2 <th>)
|
32
|
+
fail ResponseError, 'Unknown HTML' unless table_rows&.size == 16
|
33
|
+
table_rows.lazy.drop(2).map(&:children).map do |row|
|
34
|
+
row.map(&:text).map(&:strip)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Parse the #raw_exchange_rates returned in response
|
39
|
+
# @param [Array] of the raw_data scraped
|
40
|
+
# @return [Hash] of exchange rates for selling and buying
|
41
|
+
# {
|
42
|
+
# { sell: { SYM: rate }, { SYM: rate }, ... },
|
43
|
+
# { buy: { SYM: rate }, { SYM: rate }, ... }
|
44
|
+
# }
|
45
|
+
def parse(raw_data)
|
46
|
+
raw_data.each_with_object(sell: {}, buy: {}) do |row, result|
|
47
|
+
sell_rate = row[11].to_f
|
48
|
+
buy_rate = row[9].to_f
|
49
|
+
currency = row[1][0..2].to_sym
|
50
|
+
currency = :JPY if currency == '100'.to_sym
|
51
|
+
|
52
|
+
result[:sell][currency] = sell_rate
|
53
|
+
result[:buy][currency] = buy_rate
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/egp_rates/cae.rb
CHANGED
@@ -26,8 +26,6 @@ module EGPRates
|
|
26
26
|
# ...
|
27
27
|
# ]
|
28
28
|
def raw_exchange_rates
|
29
|
-
response = Net::HTTP.get_response(@uri)
|
30
|
-
fail ResponseError, response.code unless response.is_a? Net::HTTPSuccess
|
31
29
|
table_rows = Oga.parse_html(response.body).css('#f_box option')
|
32
30
|
# CAE porvide 17 currencies on the home page but with header
|
33
31
|
# and an empty row in the end
|
data/lib/egp_rates/cbe.rb
CHANGED
@@ -32,25 +32,5 @@ module EGPRates
|
|
32
32
|
fail ResponseError, 'Unknown HTML' unless table_rows&.size == 9
|
33
33
|
table_rows.lazy.map(&:children).map { |cell| cell.map(&:text) }
|
34
34
|
end
|
35
|
-
|
36
|
-
# Convert currency string to ISO symbol
|
37
|
-
# @param currency [String] "US Dollar"
|
38
|
-
# @return [Symbol] :USD ISO currency name
|
39
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
40
|
-
def currency_symbol(currency)
|
41
|
-
case currency
|
42
|
-
when /US Dollar/ then :USD
|
43
|
-
when /Euro/ then :EUR
|
44
|
-
when /Sterling/ then :GBP
|
45
|
-
when /Swiss/ then :CHF
|
46
|
-
when /Japanese/ then :JPY
|
47
|
-
when /Saudi/ then :SAR
|
48
|
-
when /Kuwait/ then :KWD
|
49
|
-
when /UAE/ then :AED
|
50
|
-
when /Chinese/ then :CNY
|
51
|
-
else fail ResponseError, "Unknown currency #{currency}"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
55
35
|
end
|
56
36
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module EGPRates
|
3
|
+
# Export Development Bank of Egypt (EDBE)
|
4
|
+
class EDBE < EGPRates::Bank
|
5
|
+
def initialize
|
6
|
+
@sym = :EDBE
|
7
|
+
@uri = URI.parse('http://www.edbebank.com/EN/BankingServices/TreasuryFiles/exchangerates.xml')
|
8
|
+
end
|
9
|
+
|
10
|
+
# @return [Hash] of exchange rates for selling and buying
|
11
|
+
# {
|
12
|
+
# { sell: { SYM: rate }, { SYM: rate }, ... },
|
13
|
+
# { buy: { SYM: rate }, { SYM: rate }, ... }
|
14
|
+
# }
|
15
|
+
def exchange_rates
|
16
|
+
@exchange_rates ||= parse(raw_exchange_rates)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
# Send the request to the URL and retrun raw data of the response
|
22
|
+
# @return [Array<Oga::XML::Attribute>]
|
23
|
+
# [
|
24
|
+
# Attribute(name: "USDBbuy" value: "17.2500"),
|
25
|
+
# Attribute(name: "USDBsell" value: "17.7000"),
|
26
|
+
# Attribute(name: "USDTbuy" value: "17.2500"),
|
27
|
+
# Attribute(name: "USDTsell" value: "17.6000"),
|
28
|
+
# ...
|
29
|
+
# ]
|
30
|
+
def raw_exchange_rates
|
31
|
+
table_rows = Oga.parse_xml(response.body).xpath('Details/rates')
|
32
|
+
# EDBE porvide 5 as 20 XML attributes
|
33
|
+
fail ResponseError, 'Unknown HTML' unless table_rows&.size == 1
|
34
|
+
table_rows.flat_map(&:attributes).take(20)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Parse the #raw_exchange_rates returned in response
|
38
|
+
# @param [Array] of the raw_data scraped
|
39
|
+
# @return [Hash] of exchange rates for selling and buying
|
40
|
+
# {
|
41
|
+
# { sell: { SYM: rate }, { SYM: rate }, ... },
|
42
|
+
# { buy: { SYM: rate }, { SYM: rate }, ... }
|
43
|
+
# }
|
44
|
+
def parse(raw_data)
|
45
|
+
raw_data.each_with_object(sell: {}, buy: {}) do |row, result|
|
46
|
+
next unless row.name[3] == 'B'
|
47
|
+
currency = row.name[0..2].to_sym
|
48
|
+
action = row.name[4..-1].to_sym
|
49
|
+
action_rate = row.value.to_f
|
50
|
+
action_rate = (action_rate * 100).round(4) if currency == :JPY
|
51
|
+
|
52
|
+
result[action][currency] = action_rate
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module EGPRates
|
3
|
+
# Egyptian Gulf Bank (EGB)
|
4
|
+
class EGB < EGPRates::Bank
|
5
|
+
def initialize
|
6
|
+
@sym = :EGB
|
7
|
+
@uri = URI.parse('https://eg-bank.com/ExchangeRates/ExchangeRates/')
|
8
|
+
end
|
9
|
+
|
10
|
+
# @return [Hash] of exchange rates for selling and buying
|
11
|
+
# {
|
12
|
+
# { sell: { SYM: rate }, { SYM: rate }, ... },
|
13
|
+
# { buy: { SYM: rate }, { SYM: rate }, ... }
|
14
|
+
# }
|
15
|
+
def exchange_rates
|
16
|
+
@exchange_rates ||= parse(raw_exchange_rates)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
# Send the request to the URL and retrun raw data of the response
|
22
|
+
# @return [Enumerator::Lazy] with the table row in HTML that evaluates to
|
23
|
+
# [
|
24
|
+
# ["", "USD", "", "17.00", "", "17.75", ""],
|
25
|
+
# ["", "EUR", "", "17.9639", "", "18.8896", ""],
|
26
|
+
# ["", "GBP", "", "20.9049", "", "22.0739", ""],
|
27
|
+
# ...
|
28
|
+
# ]
|
29
|
+
def raw_exchange_rates
|
30
|
+
table_rows = Oga.parse_html(response.body).css('.row.row-wrapper')
|
31
|
+
# EGB porvide 17 currencies (and a header row)
|
32
|
+
fail ResponseError, 'Unknown HTML' unless table_rows&.size == 18
|
33
|
+
table_rows.lazy.drop(1).map(&:children).map do |cell|
|
34
|
+
cell.map(&:text).map(&:strip)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Parse the #raw_exchange_rates returned in response
|
39
|
+
# @param [Array] of the raw_data scraped
|
40
|
+
# @return [Hash] of exchange rates for selling and buying
|
41
|
+
# {
|
42
|
+
# { sell: { SYM: rate }, { SYM: rate }, ... },
|
43
|
+
# { buy: { SYM: rate }, { SYM: rate }, ... }
|
44
|
+
# }
|
45
|
+
def parse(raw_data)
|
46
|
+
raw_data.each_with_object(sell: {}, buy: {}) do |row, result|
|
47
|
+
sell_rate = row[5].to_f
|
48
|
+
buy_rate = row[3].to_f
|
49
|
+
currency = row[1].to_sym
|
50
|
+
|
51
|
+
result[:sell][currency] = sell_rate
|
52
|
+
result[:buy][currency] = buy_rate
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module EGPRates
|
3
|
+
# Faisal Islamic Bank of Egypt
|
4
|
+
class FaisalBank < EGPRates::Bank
|
5
|
+
def initialize
|
6
|
+
@sym = :FaisalBank
|
7
|
+
@uri = URI.parse('http://www.faisalbank.com.eg/FIB/arabic/rate.html')
|
8
|
+
end
|
9
|
+
|
10
|
+
# @return [Hash] of exchange rates for selling and buying
|
11
|
+
# {
|
12
|
+
# { sell: { SYM: rate }, { SYM: rate }, ... },
|
13
|
+
# { buy: { SYM: rate }, { SYM: rate }, ... }
|
14
|
+
# }
|
15
|
+
def exchange_rates
|
16
|
+
@exchange_rates ||= parse(raw_exchange_rates)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
# Send the request to the URL and retrun raw data of the response
|
22
|
+
# @return [Enumerator::Lazy] with the table row in HTML that evaluates to
|
23
|
+
# [
|
24
|
+
# ["", "USD", "", "17.2500", "", "17.7500", ...]
|
25
|
+
# ["", "SAR", "", "4.5745", "", "4.7849" ... ]
|
26
|
+
# ...
|
27
|
+
# ]
|
28
|
+
def raw_exchange_rates
|
29
|
+
table_rows = Oga.parse_html(response.body).css('.even')
|
30
|
+
# FaisalBank porvide 13 currencies
|
31
|
+
fail ResponseError, 'Unknown HTML' unless table_rows&.size == 13
|
32
|
+
table_rows.lazy.map(&:children).map do |cell|
|
33
|
+
cell.to_a.drop(2).map(&:text).map(&:strip)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Parse the #raw_exchange_rates returned in response
|
38
|
+
# @param [Array] of the raw_data scraped
|
39
|
+
# @return [Hash] of exchange rates for selling and buying
|
40
|
+
# {
|
41
|
+
# { sell: { SYM: rate }, { SYM: rate }, ... },
|
42
|
+
# { buy: { SYM: rate }, { SYM: rate }, ... }
|
43
|
+
# }
|
44
|
+
def parse(raw_data)
|
45
|
+
raw_data.each_with_object(sell: {}, buy: {}) do |row, result|
|
46
|
+
sell_rate = row[5].to_f
|
47
|
+
buy_rate = row[3].to_f
|
48
|
+
currency = row[1].to_sym
|
49
|
+
|
50
|
+
result[:sell][currency] = sell_rate
|
51
|
+
result[:buy][currency] = buy_rate
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/egp_rates/midb.rb
CHANGED
@@ -29,8 +29,6 @@ module EGPRates
|
|
29
29
|
# ...
|
30
30
|
# ]
|
31
31
|
def raw_exchange_rates
|
32
|
-
response = Net::HTTP.get_response(@uri)
|
33
|
-
fail ResponseError, response.code unless response.is_a? Net::HTTPSuccess
|
34
32
|
table_rows = Oga.parse_html(response.body)
|
35
33
|
.css('#MainContent_grdcurrency tr')
|
36
34
|
# MIDB porvide 7 currencies on the home page but with header
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module EGPRates
|
3
|
+
# National Bank of Greece (NBG)
|
4
|
+
class NBG < EGPRates::Bank
|
5
|
+
def initialize
|
6
|
+
@sym = :NBG
|
7
|
+
@uri = URI.parse('http://www.nbg.com.eg/en/exchange-rates')
|
8
|
+
end
|
9
|
+
|
10
|
+
# @return [Hash] of exchange rates for selling and buying
|
11
|
+
# {
|
12
|
+
# { sell: { SYM: rate }, { SYM: rate }, ... },
|
13
|
+
# { buy: { SYM: rate }, { SYM: rate }, ... }
|
14
|
+
# }
|
15
|
+
def exchange_rates
|
16
|
+
@exchange_rates ||= parse(raw_exchange_rates)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
# Send the request to the URL and retrun raw data of the response
|
22
|
+
# @return [Enumerator::Lazy] with the table row in HTML that evaluates to
|
23
|
+
# [
|
24
|
+
# ["", "US Dollar", "", "USD", "", "17.2000", "", "17.8000", ...]
|
25
|
+
# ["", "Euro", "", "EUR", "", "18.1030", "", "18.3039", ... ]
|
26
|
+
# ...
|
27
|
+
# ]
|
28
|
+
def raw_exchange_rates
|
29
|
+
table_rows = Oga.parse_html(response.body).css('.row_exchange')
|
30
|
+
# NBG porvide 9 currencies (and 2 header rows)
|
31
|
+
fail ResponseError, 'Unknown HTML' unless table_rows&.size == 11
|
32
|
+
table_rows.lazy.drop(2).map(&:children).map do |cell|
|
33
|
+
cell.map(&:text).map(&:strip)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Parse the #raw_exchange_rates returned in response
|
38
|
+
# @param [Array] of the raw_data scraped
|
39
|
+
# @return [Hash] of exchange rates for selling and buying
|
40
|
+
# {
|
41
|
+
# { sell: { SYM: rate }, { SYM: rate }, ... },
|
42
|
+
# { buy: { SYM: rate }, { SYM: rate }, ... }
|
43
|
+
# }
|
44
|
+
def parse(raw_data)
|
45
|
+
raw_data.each_with_object(sell: {}, buy: {}) do |row, result|
|
46
|
+
sell_rate = row[7].to_f
|
47
|
+
buy_rate = row[5].to_f
|
48
|
+
currency = row[3].to_sym
|
49
|
+
|
50
|
+
result[:sell][currency] = sell_rate
|
51
|
+
result[:buy][currency] = buy_rate
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/egp_rates/saib.rb
CHANGED
@@ -30,8 +30,6 @@ module EGPRates
|
|
30
30
|
# ]
|
31
31
|
#
|
32
32
|
def raw_exchange_rates
|
33
|
-
response = Net::HTTP.get_response(@uri)
|
34
|
-
fail ResponseError, response.code unless response.is_a? Net::HTTPSuccess
|
35
33
|
table_rows = Oga.parse_html(response.body).css('.cont table tbody tr')
|
36
34
|
# SAIB porvide 6 currencies on the home page but with header
|
37
35
|
# and an empty row in the end
|
@@ -36,29 +36,6 @@ module EGPRates
|
|
36
36
|
end
|
37
37
|
# rubocop:enable Style/MultilineMethodCallIndentation
|
38
38
|
|
39
|
-
# Convert currency string to ISO symbol
|
40
|
-
# @param currency [String] "US Dollar"
|
41
|
-
# @return [Symbol] :USD ISO currency name
|
42
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
43
|
-
def currency_symbol(currency)
|
44
|
-
case currency
|
45
|
-
when /UAE Dirham/ then :AED
|
46
|
-
when /Australian/ then :AUD
|
47
|
-
when /Canadian/ then :CAD
|
48
|
-
when /Swiss/ then :CHF
|
49
|
-
when /Danish/ then :DKK
|
50
|
-
when /EUR/ then :EUR
|
51
|
-
when /Sterling/ then :GBP
|
52
|
-
when /YEN/ then :JPY
|
53
|
-
when /Kuwaiti/ then :KWD
|
54
|
-
when /Norwegian/ then :NOK
|
55
|
-
when /Saudi/ then :SAR
|
56
|
-
when /Swedish/ then :SEK
|
57
|
-
when /US Dollar/ then :USD
|
58
|
-
else fail ResponseError, "Unknown currency #{currency}"
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
39
|
# Parse the #raw_exchange_rates returned in response
|
63
40
|
# @param [Array] of the raw_data scraped
|
64
41
|
# @return [Hash] of exchange rates for selling and buying
|
data/lib/egp_rates/ube.rb
CHANGED
@@ -29,8 +29,6 @@ module EGPRates
|
|
29
29
|
# ...
|
30
30
|
# ]
|
31
31
|
def raw_exchange_rates
|
32
|
-
response = Net::HTTP.get_response(@uri)
|
33
|
-
fail ResponseError, response.code unless response.is_a? Net::HTTPSuccess
|
34
32
|
table_rows = Oga.parse_html(response.body).css('table tr')
|
35
33
|
# UBE porvide 6 currencies on the home page but with header
|
36
34
|
# and an empty row in the end
|