currency_quote 0.1.2 → 0.1.7

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: 8ae43131b099eed65bb04af747c645194237d2381e164578d663a40407d11f52
4
- data.tar.gz: 96a40a3cfd66b9a649bc5dcdee633a54fb89a6f41497ee6ccd0065a5a3048a3c
3
+ metadata.gz: b5b18309249ed756d407c332b6b2f9d94f9f1f66b00ee3de1fda96b812da3853
4
+ data.tar.gz: 2b770235571cdd10fcad5f1d78ed4f0a71bd94e6c43749a7ef68fad466138db9
5
5
  SHA512:
6
- metadata.gz: f7d4da86ee07d734c03813c288bcdeabff2d948b8fb8a0a56d0263a0bfba2b73e27b3ae38adaf3f1725cb2db0c4ce84735830225017d52c1f03c1100bd8601bc
7
- data.tar.gz: 7b76091240025a5af2eef158fe6a691d34503feeb50db249ab369e5d6cc805f62d6d17b3af2f5d3754207641b6b1500b6aedd4ceb4eec7899268913276238617
6
+ metadata.gz: 5d62e4e79f1e5eff18b3abe03e8c520ed935721d8c0d9e5a908bf8a10ae091474dc0aa6cc7dd79da6ebf42c9b8b7e73d845fe9c465b78900859d39ed5393127a
7
+ data.tar.gz: c7c5e006a97dc8cad4dde90b78a3856b6e38dc31ac717735576fc2b42444de78d42426f96f7d5e9e2856dc08bf74999b09535bf37c3a8ec223e78eb309cb7977
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- currency_quote (0.1.1)
4
+ currency_quote (0.1.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,9 +1,6 @@
1
1
  require_relative "currency_quote/version"
2
2
  require_relative "currency_quote/dolar"
3
3
  require_relative "currency_quote/currency"
4
- require_relative "support/hash.rb"
5
- require_relative "support/string.rb"
6
- require_relative "support/symbol.rb"
7
4
 
8
5
  module CurrencyQuote
9
6
  class Error < StandardError; end
@@ -14,10 +14,14 @@ class CurrencyQuote::Currency
14
14
  end
15
15
 
16
16
  def get_quotation
17
- get_dolar_quotation
18
- make_get_to_bcra
19
- get_currency_quotation
20
- return struct
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
21
25
  end
22
26
 
23
27
  private
@@ -34,10 +38,14 @@ class CurrencyQuote::Currency
34
38
  def get_currency_quotation
35
39
  data = @doc.css("td").map(&:text).collect(&:strip!)
36
40
  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
+ 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
41
49
  end
42
50
 
43
51
  def struct
@@ -2,6 +2,7 @@ class CurrencyQuote::Dolar
2
2
  require 'open-uri'
3
3
  require 'nokogiri'
4
4
  require 'date'
5
+ require "addressable/uri"
5
6
 
6
7
  attr_accessor :date, :doc, :sell, :buy
7
8
 
@@ -20,14 +21,14 @@ class CurrencyQuote::Dolar
20
21
  private
21
22
 
22
23
  def make_get_to_bna
23
-
24
- opts = {
24
+ params = Addressable::URI.new
25
+ params.query_values = {
25
26
  id: 'billetes',
26
27
  fecha: date,
27
28
  filtroEuro: 0,
28
29
  filtroDolar: 1
29
30
  }
30
- url = "#{BASE_URL}?#{opts.to_param}"
31
+ url = "#{BASE_URL}?#{params.query}"
31
32
 
32
33
  @doc = Nokogiri::HTML( URI.open(url) )
33
34
  end
@@ -35,8 +36,8 @@ class CurrencyQuote::Dolar
35
36
  def extract_data
36
37
  data = @doc.css("td").map(&:text)
37
38
  @date = data[data.size - 1]
38
- @sell = data[data.size - 2].to_f
39
- @buy = data[data.size - 3].to_f
39
+ @sell = data[data.size - 2].gsub(",", ".").to_f
40
+ @buy = data[data.size - 3].gsub(",", ".").to_f
40
41
  end
41
42
 
42
43
  def struct
@@ -1,3 +1,3 @@
1
1
  module CurrencyQuote
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: currency_quote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Facundo A. Díaz Martínez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-16 00:00:00.000000000 Z
11
+ date: 2020-11-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -34,9 +34,6 @@ files:
34
34
  - lib/currency_quote/currency.rb
35
35
  - lib/currency_quote/dolar.rb
36
36
  - lib/currency_quote/version.rb
37
- - lib/support/hash.rb
38
- - lib/support/string.rb
39
- - lib/support/symbol.rb
40
37
  homepage: https://www.sesocio.com
41
38
  licenses:
42
39
  - MIT
@@ -1,12 +0,0 @@
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
@@ -1,8 +0,0 @@
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
@@ -1,8 +0,0 @@
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