currency_quote 0.1.0 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +51 -0
- data/.ruby-version +1 -0
- data/Gemfile.lock +38 -0
- data/README.md +44 -2
- data/lib/currency_quote/currency.rb +55 -0
- data/lib/currency_quote/dolar.rb +46 -0
- data/lib/currency_quote/version.rb +1 -1
- data/lib/support/hash.rb +12 -0
- data/lib/support/string.rb +8 -0
- data/lib/support/symbol.rb +8 -0
- metadata +8 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6eb28e36b9639588febc4fb586d7427b948174992ed74a8eb0cb2710e44f6003
|
4
|
+
data.tar.gz: e6a0b640af6bd565680e2ada442cca52311834e824964b2cea8538d9114485f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb1fb334786f7451e88d6d1484e60f22d8c519a3d992f27438d26cd1f5d7c44a52af1532a52d35fc44ef35ce76f1a30460695238782a33dc9d0408ea11d8741d
|
7
|
+
data.tar.gz: fb9793f9fc5c6cb51aee4491d5374445ad837a4d3c09c7a17483a4cc17aef6c8f4967852bd05e20a356bf0a35644b1ed2c00def53aba000b58c5244e670dd722
|
data/.gitignore
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
|
1
2
|
/.bundle/
|
2
3
|
/.yardoc
|
3
4
|
/_yardoc/
|
@@ -9,3 +10,53 @@
|
|
9
10
|
|
10
11
|
# rspec failure tracking
|
11
12
|
.rspec_status
|
13
|
+
# These are some examples of commonly ignored file patterns.
|
14
|
+
# You should customize this list as applicable to your project.
|
15
|
+
# Learn more about .gitignore:
|
16
|
+
# https://www.atlassian.com/git/tutorials/saving-changes/gitignore
|
17
|
+
|
18
|
+
# Node artifact files
|
19
|
+
node_modules/
|
20
|
+
dist/
|
21
|
+
|
22
|
+
# Compiled Java class files
|
23
|
+
*.class
|
24
|
+
|
25
|
+
# Compiled Python bytecode
|
26
|
+
*.py[cod]
|
27
|
+
|
28
|
+
# Log files
|
29
|
+
*.log
|
30
|
+
|
31
|
+
# Package files
|
32
|
+
*.jar
|
33
|
+
|
34
|
+
# Maven
|
35
|
+
target/
|
36
|
+
dist/
|
37
|
+
|
38
|
+
# JetBrains IDE
|
39
|
+
.idea/
|
40
|
+
|
41
|
+
# Unit test reports
|
42
|
+
TEST*.xml
|
43
|
+
|
44
|
+
# Generated by MacOS
|
45
|
+
.DS_Store
|
46
|
+
|
47
|
+
# Generated by Windows
|
48
|
+
Thumbs.db
|
49
|
+
|
50
|
+
# Applications
|
51
|
+
*.app
|
52
|
+
*.exe
|
53
|
+
*.war
|
54
|
+
|
55
|
+
# Large media files
|
56
|
+
*.mp4
|
57
|
+
*.tiff
|
58
|
+
*.avi
|
59
|
+
*.flv
|
60
|
+
*.mov
|
61
|
+
*.wmv
|
62
|
+
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.1
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
currency_quote (0.1.4)
|
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
|
data/README.md
CHANGED
@@ -22,8 +22,50 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
### Cotizaciones disponibles
|
26
|
+
Bolívar Venezolano,
|
27
|
+
Cordoba Nicaraguense,
|
28
|
+
Corona Checa,
|
29
|
+
Corona Danesa,
|
30
|
+
Corona Noruega,
|
31
|
+
Corona Sueca,
|
32
|
+
Derecho Especial de Giro,
|
33
|
+
Dinar Serbia,
|
34
|
+
Dolar Australiano,
|
35
|
+
Dolar Canadiense,
|
36
|
+
Dolar de Singapur,
|
37
|
+
Dolar Estadounidense,
|
38
|
+
Dolar Hong Kong,
|
39
|
+
Dolar Neozelandes,
|
40
|
+
Euro (Unidad Monetaria Europe,
|
41
|
+
Florin (Antillas Holandesas),
|
42
|
+
Franco Suizo,
|
43
|
+
Guaraní Paraguayo,
|
44
|
+
Libra Esterlina,
|
45
|
+
Lira Turca,
|
46
|
+
Nuevo Sol Peruano,
|
47
|
+
Oro - Onza Troy,
|
48
|
+
Peso,
|
49
|
+
Peso Boliviano,
|
50
|
+
Peso Chileno,
|
51
|
+
Peso Colombiano,
|
52
|
+
Peso Mexicano,
|
53
|
+
Peso Uruguayo,
|
54
|
+
Plata - Onza Troy,
|
55
|
+
Rand Sudafricano,
|
56
|
+
Real (Brasil),
|
57
|
+
Rublo (Rusia),
|
58
|
+
Rupia (India),
|
59
|
+
Shekel (Israel),
|
60
|
+
Yen (Japón),
|
61
|
+
Yuan- China CNY,
|
62
|
+
Yuan-China Off Shore CNH
|
63
|
+
|
64
|
+
### Obtener cotización
|
65
|
+
quotation = CurrencyQuote::Currency.new(currency: "Peso Colombiano", date: "13/11/2020").get_quotation
|
66
|
+
|
67
|
+
Devuelve
|
68
|
+
$ #<struct Struct::Currency currency="Peso Colombiano", date="13/11/2020", sell=0.023289999999999998, buy=0.021646>
|
27
69
|
## Development
|
28
70
|
|
29
71
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -0,0 +1,55 @@
|
|
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
|
+
if currency == "Dolar Estadounidense"
|
18
|
+
return get_dolar_quotation
|
19
|
+
else
|
20
|
+
get_dolar_quotation
|
21
|
+
make_get_to_bcra
|
22
|
+
get_currency_quotation
|
23
|
+
return struct
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def get_dolar_quotation
|
30
|
+
@dolar = CurrencyQuote::Dolar.new(date: date).get_quotation
|
31
|
+
end
|
32
|
+
|
33
|
+
def make_get_to_bcra
|
34
|
+
url = "#{BASE_URL}?date2=#{date}"
|
35
|
+
@doc = Nokogiri::HTML( URI.open(url) )
|
36
|
+
end
|
37
|
+
|
38
|
+
def get_currency_quotation
|
39
|
+
data = @doc.css("td").map(&:text).collect(&:strip!)
|
40
|
+
index = data.index(currency)
|
41
|
+
if index
|
42
|
+
quote = data[index + 1].gsub(",", ".").to_f
|
43
|
+
quote = 1.0 if quote == 0
|
44
|
+
@sell = (dolar.sell * quote).to_f
|
45
|
+
@buy = (dolar.buy * quote).to_f
|
46
|
+
else
|
47
|
+
@sell = @buy = 0
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def struct
|
52
|
+
s = Struct.new(:currency, :date, :sell, :buy)
|
53
|
+
s.new(currency, date, sell, buy)
|
54
|
+
end
|
55
|
+
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
|
+
data = @doc.css("td").map(&:text)
|
37
|
+
@date = data[data.size - 1]
|
38
|
+
@sell = data[data.size - 2].gsub(",", ".").to_f
|
39
|
+
@buy = data[data.size - 3].gsub(",", ".").to_f
|
40
|
+
end
|
41
|
+
|
42
|
+
def struct
|
43
|
+
s = Struct.new(:date, :sell, :buy)
|
44
|
+
s.new(date, sell, buy)
|
45
|
+
end
|
46
|
+
end
|
data/lib/support/hash.rb
ADDED
@@ -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
|
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.
|
4
|
+
version: 0.1.5
|
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
|