currency_quote 0.1.0 → 0.1.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: aff166c1ee7797b011246dcc9f2ef4197ddd755900530b27fb3877109ae8de43
4
- data.tar.gz: c7c87b754ba1084cf2f6dd8b0b5eedf2dacd020612f6df2a4c2fb557f88b2c45
3
+ metadata.gz: 8b3a925a5d95f3ad13788d2555eb01c55233c0efac1b3034a9b01a17968c0778
4
+ data.tar.gz: 93485459ac19ed96afccf6385d0718f1ea042eb7c3abaaec1050d121d499dccf
5
5
  SHA512:
6
- metadata.gz: 9a4eaddddb0aba0604a47845c564bddf71db5b11fb924d5627675d501061096465582bda3179b707092371b12b920465bd2c5b28aa5ef60d02e2658e82ef442c
7
- data.tar.gz: 474d7a059e397da0617c6de5857c3baea34c2789017e5db335e9cde0967eb2ce0c06169e955a1893e5baf202d01acd9408fcd8ee2053bea2520e23ddc09f669a
6
+ metadata.gz: 7aabe115fdc4ccc31613ab9594d6fa1749d35e614d77fca8af6709c0e66316a5177f35dcf5ee29316a7fbb9ea9bb8dfb4317dcf081fceae1037c376324b19383
7
+ data.tar.gz: 8657395aec99bed986dbf92927b0d78aa632909966c7b2c498db0a4939428684a1259f8bbd032de97b5680f00a81413434041f6170017d0be56d9f82ecf0c602
@@ -0,0 +1 @@
1
+ 2.7.1
@@ -0,0 +1,38 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ currency_quote (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.4.4)
10
+ mini_portile2 (2.4.0)
11
+ nokogiri (1.10.10)
12
+ mini_portile2 (~> 2.4.0)
13
+ rake (12.3.3)
14
+ rspec (3.10.0)
15
+ rspec-core (~> 3.10.0)
16
+ rspec-expectations (~> 3.10.0)
17
+ rspec-mocks (~> 3.10.0)
18
+ rspec-core (3.10.0)
19
+ rspec-support (~> 3.10.0)
20
+ rspec-expectations (3.10.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.10.0)
23
+ rspec-mocks (3.10.0)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.10.0)
26
+ rspec-support (3.10.0)
27
+
28
+ PLATFORMS
29
+ ruby
30
+
31
+ DEPENDENCIES
32
+ currency_quote!
33
+ nokogiri (~> 1.10)
34
+ rake (~> 12.0)
35
+ rspec (~> 3.0)
36
+
37
+ BUNDLED WITH
38
+ 2.1.4
@@ -0,0 +1,47 @@
1
+ class CurrencyQuote::Currency
2
+ require 'open-uri'
3
+ require 'nokogiri'
4
+ require 'date'
5
+
6
+ attr_accessor :currency, :date, :dolar, :doc, :sell, :buy
7
+
8
+ BASE_URL = "https://www.bcra.gob.ar/publicacionesestadisticas/Cotizaciones_por_fecha_2.asp"
9
+
10
+ def initialize(currency:, date: )
11
+ @currency = currency
12
+ @date = date
13
+ @dolar = dolar
14
+ end
15
+
16
+ def get_quotation
17
+ get_dolar_quotation
18
+ make_get_to_bcra
19
+ get_currency_quotation
20
+ return struct
21
+ end
22
+
23
+ private
24
+
25
+ def get_dolar_quotation
26
+ @dolar = CurrencyQuote::Dolar.new(date: date).get_quotation
27
+ end
28
+
29
+ def make_get_to_bcra
30
+ url = "#{BASE_URL}?date2=#{date}"
31
+ @doc = Nokogiri::HTML( URI.open(url) )
32
+ end
33
+
34
+ def get_currency_quotation
35
+ data = @doc.css("td").map(&:text).collect(&:strip!)
36
+ index = data.index(currency)
37
+ quote = data[index + 1].gsub(",", ".").to_f
38
+ quote = 1 if quote == 0
39
+ @sell = (dolar.sell * quote).to_f
40
+ @buy = (dolar.buy * quote).to_f
41
+ end
42
+
43
+ def struct
44
+ s = Struct.new("Currency", :currency, :date, :sell, :buy)
45
+ s.new(currency, date, sell, buy)
46
+ end
47
+ end
@@ -0,0 +1,46 @@
1
+ class CurrencyQuote::Dolar
2
+ require 'open-uri'
3
+ require 'nokogiri'
4
+ require 'date'
5
+
6
+ attr_accessor :date, :doc, :sell, :buy
7
+
8
+ BASE_URL = "https://www.bna.com.ar/Cotizador/HistoricoPrincipales"
9
+
10
+ def initialize(date:)
11
+ @date = date
12
+ end
13
+
14
+ def get_quotation
15
+ make_get_to_bna
16
+ extract_data
17
+ return struct
18
+ end
19
+
20
+ private
21
+
22
+ def make_get_to_bna
23
+
24
+ opts = {
25
+ id: 'billetes',
26
+ fecha: date,
27
+ filtroEuro: 0,
28
+ filtroDolar: 1
29
+ }
30
+ url = "#{BASE_URL}?#{opts.to_param}"
31
+
32
+ @doc = Nokogiri::HTML( URI.open(url) )
33
+ end
34
+
35
+ def extract_data
36
+ puts data = @doc.css("td").map(&:text)
37
+ @date = data[data.size - 1]
38
+ @sell = data[data.size - 2].to_f
39
+ @buy = data[data.size - 3].to_f
40
+ end
41
+
42
+ def struct
43
+ s = Struct.new("Dolar", :date, :sell, :buy)
44
+ s.new(date, sell, buy)
45
+ end
46
+ end
@@ -1,3 +1,3 @@
1
1
  module CurrencyQuote
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -0,0 +1,12 @@
1
+ class Hash
2
+
3
+ def to_query(namespace = nil)
4
+ query = collect do |key, value|
5
+ value.to_s.to_query(namespace ? "#{namespace}[#{key}]" : key)
6
+ end.compact
7
+
8
+ query.sort! unless namespace.to_s.include?("[]")
9
+ query.join("&")
10
+ end
11
+ alias_method :to_param, :to_query
12
+ end
@@ -0,0 +1,8 @@
1
+ class String
2
+ require "cgi"
3
+
4
+ def to_query(key)
5
+ "#{CGI.escape(key.to_s)}=#{CGI.escape(self)}"
6
+ end
7
+ alias_method :to_param, :to_query
8
+ end
@@ -0,0 +1,8 @@
1
+ class Symbol
2
+ require "cgi"
3
+
4
+ def to_query
5
+ CGI.escape(self.to_s)
6
+ end
7
+ alias_method :to_param, :to_query
8
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: currency_quote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Facundo A. Díaz Martínez
@@ -19,9 +19,11 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - ".gitignore"
21
21
  - ".rspec"
22
+ - ".ruby-version"
22
23
  - ".travis.yml"
23
24
  - CODE_OF_CONDUCT.md
24
25
  - Gemfile
26
+ - Gemfile.lock
25
27
  - LICENSE.txt
26
28
  - README.md
27
29
  - Rakefile
@@ -29,7 +31,12 @@ files:
29
31
  - bin/setup
30
32
  - currency_quote.gemspec
31
33
  - lib/currency_quote.rb
34
+ - lib/currency_quote/currency.rb
35
+ - lib/currency_quote/dolar.rb
32
36
  - lib/currency_quote/version.rb
37
+ - lib/support/hash.rb
38
+ - lib/support/string.rb
39
+ - lib/support/symbol.rb
33
40
  homepage: https://www.sesocio.com
34
41
  licenses:
35
42
  - MIT