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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3108e2c21aa48d68b93712bea13b69e2cf1cc4d31bc33632cbb172713f4f4d23
4
- data.tar.gz: 0e22b4646b52d28a067c6748240c27325ec0c5035fcf252f15f3f4ca5617c395
3
+ metadata.gz: 2d8d51459187279a89320164459851615e7de64e1ff9dd75d106a7322845eef0
4
+ data.tar.gz: 3427e7161337aa661489939e0b9e85c4c99748e3e3fefdbbce13f3153d5eab70
5
5
  SHA512:
6
- metadata.gz: dda16f2ff47129ea8a519dc056dbbf4713aa63c0431985e2dcba9cf290a6d8a0478291ca5d1cdfe6f8ba2d28c4cc2000f8eae9c9d6a31fc4095df2542e5e1d41
7
- data.tar.gz: 1aa79fb3641655306efaaab1c0ea3cd9cfce63f779b8e94c839d29c64427a48d4341e83b2679e7186d6c26ab65e51de910534493967bd2e5a5a72829bfaa83d4
6
+ metadata.gz: 7a4edad7f7449555932c395cdc9c8821af89e3ffe4935f0fbe361c04a251969b4b035ffac0e2953f045c6156c9d0ac0d59765fd2d963c7ce60a09de5e064752e
7
+ data.tar.gz: 82a44c06971f40161f48450fa2b2641fe32498e06ce0063121231c5a768eb4bd954dd452e4a91df78baed90fc8fbd6fcfffe12cb4177b646e62de4d4437dab18
@@ -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: @fecha, dolar_type: dolar_type, dolar_buy: data[:compra], dolar_sell: data[:venta])
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
@@ -1,5 +1,5 @@
1
1
  module Dolar
2
2
  module Bna
3
- VERSION = "1.0.8"
3
+ VERSION = "1.0.8.1"
4
4
  end
5
5
  end
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-02 00:00:00.000000000 Z
11
+ date: 2019-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: factory_bot