Class: CurrencySpy::Walutomat

Inherits:
Scraper
  • Object
show all
Defined in:
lib/currency_spy/walutomat.rb

Overview

A class designed to fetch medium currency rates from Walutomat.pl a social currency exchange platform.

Constant Summary

Constants inherited from Scraper

Scraper::RATE_DATA

Instance Attribute Summary

Attributes inherited from Scraper

#available_codes, #currency_code, #institution, #url

Instance Method Summary collapse

Methods inherited from Scraper

#fetch_rates, #page

Constructor Details

#initializeWalutomat

Constructor method. Initializes the following:

  • a url of the source

  • and the name of the source

  • a list of currency codes available



10
11
12
13
14
15
# File 'lib/currency_spy/walutomat.rb', line 10

def initialize
  super
  @url = 'http://www.walutomat.pl/rates.php'
  @institution = 'Walutomat'
  @available_codes = %w(EUR USD GBP CHF)
end

Instance Method Details

#medium_rateObject

Fetch medium rate which is calculated based on current transactions in Walutomat



18
19
20
21
22
23
24
25
26
27
# File 'lib/currency_spy/walutomat.rb', line 18

def medium_rate
  regexp = Regexp.new("#{currency_code} / PLN")
  res = nil
  page.search("//span[@name='pair']").each do |td|
    if (regexp.match(td.content))
      res = td.next_element.content.to_f
    end
  end
  return res
end

#rate_timeObject

The hour of the rate



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/currency_spy/walutomat.rb', line 30

def rate_time
  regexp = Regexp.new(currency_code)
  res = nil
  page.search("//span[@name='pair']").each do |td|
    if (regexp.match(td.content))
      hour = td.next_element.next_element.content
      res = DateTime.parse(hour)
    end
  end
  return res
end