Class: Danconia::Exchanges::BNA

Inherits:
Danconia::Exchange show all
Defined in:
lib/danconia/exchanges/bna.rb

Overview

The BNA does not provide an API to pull the rates, so this implementation scrapes the home HTML directly. Returns rates of both types, “Billetes” and “Divisas”, and only the “tipo de cambio vendedor” ones. See ‘examples/bna.rb` for a complete usage example.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Danconia::Exchange

#rate

Constructor Details

#initialize(store: Stores::InMemory.new) ⇒ BNA

Returns a new instance of BNA.



13
14
15
# File 'lib/danconia/exchanges/bna.rb', line 13

def initialize store: Stores::InMemory.new
  @store = store
end

Instance Attribute Details

#storeObject (readonly)

Returns the value of attribute store.



11
12
13
# File 'lib/danconia/exchanges/bna.rb', line 11

def store
  @store
end

Instance Method Details

#fetch_ratesObject



17
18
19
20
# File 'lib/danconia/exchanges/bna.rb', line 17

def fetch_rates
  response = Net::HTTP.get URI 'https://www.bna.com.ar/Personas'
  scrape_rates(response, 'billetes') + scrape_rates(response, 'divisas')
end

#rates(rate_type:, date: nil) ⇒ Object



26
27
28
# File 'lib/danconia/exchanges/bna.rb', line 26

def rates rate_type:, date: nil
  array_of_rates_to_hash @store.rates(rate_type: rate_type, date: date)
end

#update_rates!Object



22
23
24
# File 'lib/danconia/exchanges/bna.rb', line 22

def update_rates!
  @store.save_rates fetch_rates
end