dolar-bna 1.0.8 → 1.0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dolar/bna/exchange.rb +16 -7
- data/lib/dolar/bna/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d8d51459187279a89320164459851615e7de64e1ff9dd75d106a7322845eef0
|
4
|
+
data.tar.gz: 3427e7161337aa661489939e0b9e85c4c99748e3e3fefdbbce13f3153d5eab70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a4edad7f7449555932c395cdc9c8821af89e3ffe4935f0fbe361c04a251969b4b035ffac0e2953f045c6156c9d0ac0d59765fd2d963c7ce60a09de5e064752e
|
7
|
+
data.tar.gz: 82a44c06971f40161f48450fa2b2641fe32498e06ce0063121231c5a768eb4bd954dd452e4a91df78baed90fc8fbd6fcfffe12cb4177b646e62de4d4437dab18
|
data/lib/dolar/bna/exchange.rb
CHANGED
@@ -63,7 +63,7 @@ module Dolar
|
|
63
63
|
ddolar = get_dolar()
|
64
64
|
end
|
65
65
|
else
|
66
|
-
ddolar = {compra: query.dolar_buy, venta: query.dolar_sell}
|
66
|
+
ddolar = {compra: query.dolar_buy, venta: query.dolar_sell, fecha: query.date}
|
67
67
|
end
|
68
68
|
return ddolar
|
69
69
|
end
|
@@ -76,7 +76,7 @@ module Dolar
|
|
76
76
|
begin
|
77
77
|
Timeout.timeout(15) do
|
78
78
|
url = "http://www.bna.com.ar/Cotizador/HistoricoPrincipales?id=billetes&fecha=#{@fecha.day}%2F#{@fecha.month}%2F#{@fecha.year}&filtroEuro=0&filtroDolar=1"
|
79
|
-
value = obtain_dolar_from_html(url, mechanize, data)
|
79
|
+
value = obtain_dolar_from_html(url, mechanize, data, "billete")
|
80
80
|
return value
|
81
81
|
end
|
82
82
|
rescue => ex
|
@@ -93,7 +93,7 @@ module Dolar
|
|
93
93
|
begin
|
94
94
|
Timeout.timeout(15) do
|
95
95
|
url = "http://www.bna.com.ar/Cotizador/MonedasHistorico"
|
96
|
-
value = obtain_dolar_from_html(url, mechanize, data)
|
96
|
+
value = obtain_dolar_from_html(url, mechanize, data, "billete")
|
97
97
|
return value
|
98
98
|
end
|
99
99
|
rescue => ex
|
@@ -102,27 +102,36 @@ module Dolar
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
-
def obtain_dolar_from_html(url, mechanize, data)
|
106
|
-
|
105
|
+
def obtain_dolar_from_html(url, mechanize, data, d_type)
|
106
|
+
dolar_fecha = nil
|
107
107
|
page = mechanize.get(url)
|
108
108
|
doc = Nokogiri::HTML(page.body, "UTF-8")
|
109
109
|
doc.xpath("//td").each_with_index do |node, index|
|
110
110
|
data[index] = node.text
|
111
111
|
end
|
112
|
+
if d_type == "divisa"
|
113
|
+
divs_data = {}
|
114
|
+
doc.xpath("//div").each_with_index do |node, index|
|
115
|
+
divs_data[index] = node.text
|
116
|
+
end
|
117
|
+
dolar_fecha = divs_data[1]
|
118
|
+
end
|
112
119
|
correct_date = "#{@fecha.day.to_i}/#{@fecha.month.to_i}/#{@fecha.year.to_i}"
|
113
120
|
i = data.key(correct_date)
|
114
121
|
if !i.nil?
|
122
|
+
dolar_fecha = data[i - 3]
|
115
123
|
dolar_compra = BigDecimal(data[i - 2].tr(",", ".")).truncate(3).to_f
|
116
124
|
dolar_venta = BigDecimal(data[i - 1].tr(",", ".")).truncate(3).to_f
|
117
125
|
else
|
126
|
+
dolar_fecha = dolar_fecha.nil? ? data[3] : dolar_fecha
|
118
127
|
dolar_compra = BigDecimal(data[1].tr(",", ".")).truncate(3).to_f
|
119
128
|
dolar_venta = BigDecimal(data[2].tr(",", ".")).truncate(3).to_f
|
120
129
|
end
|
121
|
-
return {compra: dolar_compra, venta: dolar_venta}
|
130
|
+
return {compra: dolar_compra, venta: dolar_venta, fecha: dolar_fecha}
|
122
131
|
end
|
123
132
|
|
124
133
|
def save_in_db data, dolar_type
|
125
|
-
Dolar::Bna::DolarCotization.create(date:
|
134
|
+
Dolar::Bna::DolarCotization.create(date: data[:fecha], dolar_type: dolar_type, dolar_buy: data[:compra], dolar_sell: data[:venta])
|
126
135
|
end
|
127
136
|
|
128
137
|
end
|
data/lib/dolar/bna/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dolar-bna
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.8
|
4
|
+
version: 1.0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- LITECODE
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-09-
|
11
|
+
date: 2019-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: factory_bot
|