Class: CurrencySpy::DnbNord
- Defined in:
- lib/currency_spy/dnb_nord.rb
Overview
Class designed to fetch data from DnB Nord’s website.
Constant Summary
Constants inherited from Scraper
Instance Attribute Summary collapse
-
#session_date ⇒ Object
Returns the value of attribute session_date.
-
#session_no ⇒ Object
Returns the value of attribute session_no.
Attributes inherited from Scraper
#available_codes, #currency_code, #institution
Instance Method Summary collapse
-
#buy_rate ⇒ Object
Fetches the buying rate.
-
#initialize ⇒ DnbNord
constructor
Constructor.
-
#rate_time ⇒ Object
Fetches the time of given rates.
-
#sell_rate ⇒ Object
Fetches the selling rate.
-
#url ⇒ Object
Determines the correct url of the web page to fetch rates from based of the instance variable session_no.
Methods inherited from Scraper
Constructor Details
#initialize ⇒ DnbNord
Constructor. Initializes the following:
-
url is set to nil
-
institution name
-
a list of currency codes available from that source
-
session_no number of the session. There are two sessions. 1 means the first at 8:15 am and 2 means the second one held at 12:15
12 13 14 15 16 17 18 |
# File 'lib/currency_spy/dnb_nord.rb', line 12 def initialize super @url = nil @institution = 'DnB Nord' @available_codes = %w(EUR USD GBP CHF DKK NOK SEK CZK JPY HUF CAD AUD LTL) @session_no = nil end |
Instance Attribute Details
#session_date ⇒ Object
Returns the value of attribute session_date.
5 6 7 |
# File 'lib/currency_spy/dnb_nord.rb', line 5 def session_date @session_date end |
#session_no ⇒ Object
Returns the value of attribute session_no.
5 6 7 |
# File 'lib/currency_spy/dnb_nord.rb', line 5 def session_no @session_no end |
Instance Method Details
#buy_rate ⇒ Object
Fetches the buying rate
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/currency_spy/dnb_nord.rb', line 40 def buy_rate regexp = Regexp.new(currency_code) res = nil page.search("//td").each do |td| if (regexp.match(td.content)) res = td.next_element.content.to_f end end return res end |
#rate_time ⇒ Object
Fetches the time of given rates
52 53 54 55 |
# File 'lib/currency_spy/dnb_nord.rb', line 52 def rate_time hour = @session_time == 2 ? "12:15" : "08:15" DateTime.parse(hour) end |
#sell_rate ⇒ Object
Fetches the selling rate
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/currency_spy/dnb_nord.rb', line 28 def sell_rate regexp = Regexp.new(currency_code) res = nil page.search("//td").each do |td| if (regexp.match(td.content)) res = td.next_element.next_element.content.to_f end end return res end |
#url ⇒ Object
Determines the correct url of the web page to fetch rates from based of the instance variable session_no
21 22 23 24 25 |
# File 'lib/currency_spy/dnb_nord.rb', line 21 def url dnb_session_no = @session_no ||= 1 session_time = dnb_session_no == 2 ? "12:15" : "08:15" return "http://www.dnbnord.pl/pl/tabela-kursow-walut-dla-kredytow/go:godzina=#{session_time}" end |