class CurrencyQuote::Currency
Constants
- BASE_URL
Attributes
buy[RW]
currency[RW]
date[RW]
doc[RW]
dolar[RW]
quote[RW]
sell[RW]
Public Class Methods
new(currency:, date: )
click to toggle source
# File lib/currency_quote/currency.rb, line 10 def initialize(currency:, date: ) @currency = currency @date = date @dolar = dolar end
Public Instance Methods
get_quotation()
click to toggle source
# File lib/currency_quote/currency.rb, line 16 def get_quotation begin get_dolar_quotation make_get_to_bcra get_currency_quotation rescue Timeout::Error => e @sell = @buy = @quote = 0 end return struct end
Private Instance Methods
get_currency_quotation()
click to toggle source
# File lib/currency_quote/currency.rb, line 38 def get_currency_quotation data = @doc.css("td").map(&:text).collect(&:strip!) index = data.index(currency) if index pass = data[index + 1].gsub(",", ".").to_f @quote = data[index + 2].gsub(",", ".").to_f pass = 1.0 if pass == 0 @sell = (dolar.sell * pass).to_f @buy = (dolar.buy * pass).to_f else @sell = @buy = @quote = 0 end end
get_dolar_quotation()
click to toggle source
# File lib/currency_quote/currency.rb, line 29 def get_dolar_quotation @dolar = CurrencyQuote::Dolar.new(date: date).get_quotation end
make_get_to_bcra()
click to toggle source
# File lib/currency_quote/currency.rb, line 33 def make_get_to_bcra url = "#{BASE_URL}?date2=#{date}" @doc = Nokogiri::HTML( open(url) ) end
struct()
click to toggle source
# File lib/currency_quote/currency.rb, line 52 def struct s = Struct.new(:currency, :date, :sell, :buy, :quote) s.new(currency, date, sell, buy, quote) end