Class: Dolar::Bna::Exchange
- Inherits:
-
Object
- Object
- Dolar::Bna::Exchange
- Defined in:
- lib/dolar/bna/exchange.rb
Instance Method Summary collapse
-
#initialize(fecha = Date.today) ⇒ Exchange
constructor
A new instance of Exchange.
- #perform_bna_billete ⇒ Object
- #perform_bna_divisa ⇒ Object
- #variation_billete ⇒ Object
Constructor Details
#initialize(fecha = Date.today) ⇒ Exchange
Returns a new instance of Exchange.
8 9 10 |
# File 'lib/dolar/bna/exchange.rb', line 8 def initialize(fecha=Date.today) @fecha ||= fecha end |
Instance Method Details
#perform_bna_billete ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/dolar/bna/exchange.rb', line 12 def perform_bna_billete begin Timeout.timeout(15) do data = check_cotization("Billete", @fecha) save_in_db(data, "Billete") unless data.blank? return data end rescue => ex pp ex. return nil end end |
#perform_bna_divisa ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/dolar/bna/exchange.rb', line 25 def perform_bna_divisa begin Timeout.timeout(15) do data = check_cotization("Divisa", @fecha) save_in_db(data, "Divisa") unless data.blank? return data end rescue => ex pp ex. return nil end end |
#variation_billete ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/dolar/bna/exchange.rb', line 38 def variation_billete begin Timeout.timeout(15) do today_dolar = check_cotization("Billete", @fecha) yesterday_dolar = check_cotization("Billete", (@fecha - 1.days)) unless (today_dolar.nil? || yesterday_dolar.nil?) porcentual_variation = ((today_dolar[:venta] - yesterday_dolar[:venta]) / (yesterday_dolar[:venta])) porcentual_variation = "#{(porcentual_variation * 100).round(2)}%" return porcentual_variation else return "0%" end end rescue => ex pp ex. return nil end end |