hg-finance 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b8c3c29ec2ee03c3d9fe913e153681e16b44dae0
4
- data.tar.gz: 53eac99f9645eef8b4ada3fdd5237de6412be636
3
+ metadata.gz: 6f8ffbd0d3bfd32653d773159cfd50288426c47d
4
+ data.tar.gz: c336027e36d2347e03736e956b021b122be4e4cd
5
5
  SHA512:
6
- metadata.gz: 0966553e351939fa13826ab5ac29ce2e4cb50e6d334fe9d27c167058af15fab9e7e46ca65a13ee8c005bc7a88248f12be490d569e50609914a18edebb8891e24
7
- data.tar.gz: 8c7005b4e5b3ad0ea79fa510541adcdbbb2e76797aef3bc26cfb4bc7989fe959362076f7fea12f96767d6b1044466e5e64a91b36f945a5151fcb7031f1bd2a6a
6
+ metadata.gz: 751156c1915288f8bf1be63c5e24d7b551dff9fefcaa5a9a0ea6e122c15325d70c4cfb58400aa5fc257cb21a59ecc75d3b81047473dc3a46d1c8ecc12046daac
7
+ data.tar.gz: ab3c7651daa47b85e1af34adf9cfd680fa4e06a0480c5e2bd9cefc6c2c92a9f6c03449b56ed917253e57e51099cdcb1cb7e491978cc17921d8348bd25ff8a2b4
@@ -0,0 +1,63 @@
1
+ require 'hg/finance/locale'
2
+
3
+ module HG
4
+ module Finance
5
+
6
+ class CryptoCurrency
7
+ # Public: Exchange
8
+ attr_accessor :exchange
9
+
10
+ # Public: Name
11
+ attr_accessor :name
12
+
13
+ # Public: ISO code
14
+ attr_accessor :iso_code
15
+
16
+ # Public: To currency
17
+ attr_accessor :to_currency
18
+
19
+ # Public: Price to buy
20
+ attr_accessor :buy
21
+
22
+ # Public: Price to seel
23
+ attr_accessor :sell
24
+
25
+ # Public: Last ticker
26
+ attr_accessor :last
27
+
28
+ # Public: Last day variation
29
+ attr_accessor :variation
30
+
31
+ def initialize(options = {})
32
+ if options.count != 0
33
+ @exchange = options[:exchange] if options[:exchange]
34
+ @name = options[:name] if options[:name]
35
+ @iso_code = options[:iso_code] if options[:iso_code]
36
+ @to_currency = options[:to_currency] if options[:to_currency]
37
+ @buy = options[:buy].to_f if options[:buy]
38
+ @sell = options[:sell].to_f if options[:sell]
39
+ @last = options[:last].to_f if options[:last]
40
+ @variation = options[:variation].to_f if options[:variation]
41
+ end
42
+ end
43
+
44
+ def to_s separator = ' - '
45
+ to_return = []
46
+
47
+ to_return << self.exchange.to_s + ' (' + self.iso_code.to_s + ' to ' + self.to_currency + ')'
48
+
49
+ to_return << "#{Locale.get_format(:last).to_s.capitalize}: " + "#{self.to_currency} #{self.last}" if self.last
50
+ to_return << "#{Locale.get_format(:buy).to_s.capitalize}: " + "#{self.to_currency} #{self.buy}" if self.buy
51
+ to_return << "#{Locale.get_format(:sell).to_s.capitalize}: " + "#{self.to_currency} #{self.sell}" if self.sell
52
+ to_return << "#{Locale.get_format(:variation).to_s.capitalize}: " + self.variation.to_s if self.variation
53
+
54
+ return to_return.join(separator)
55
+ end
56
+
57
+ def inspect
58
+ self.to_s
59
+ end
60
+ end
61
+
62
+ end
63
+ end
@@ -1,3 +1,4 @@
1
+ require 'hg/finance/crypto_currency'
1
2
  require 'hg/finance/currency'
2
3
  require 'hg/finance/taxes'
3
4
  require 'hg/finance/stock'
@@ -8,7 +9,7 @@ module HG
8
9
  class Data
9
10
 
10
11
  attr_accessor :request, :requested_at, :key_status
11
- attr_accessor :taxes, :currencies, :stocks
12
+ attr_accessor :taxes, :currencies, :cryptocurrencies, :stocks
12
13
 
13
14
  def initialize params, host_name, use_ssl = true
14
15
  query_params = params.map{|k,v| "#{k.to_s}=#{v.to_s}"}.join('&')
@@ -30,6 +31,11 @@ module HG
30
31
  @currencies[iso] = Currency.new(to_currency(currency, iso, results['currencies']['source']))
31
32
  end
32
33
 
34
+ @cryptocurrencies = {}
35
+ results['bitcoin'].each do |exchange, c|
36
+ @cryptocurrencies[exchange.to_sym] = { "btc#{c['format'][0]}".downcase.to_sym => CryptoCurrency.new(to_cryptocurrency(c, 'Bitcoin', 'BTC')) }
37
+ end
38
+
33
39
  @stocks = {}
34
40
  results['stocks'].each do |code, stock|
35
41
  @stocks[code] = Stock.new(to_stock(stock))
@@ -59,6 +65,19 @@ module HG
59
65
  }
60
66
  end
61
67
 
68
+ def to_cryptocurrency r, name = 'Bitcoin', iso_code = 'BTC'
69
+ {
70
+ to_currency: r['format'][0],
71
+ exchange: r['name'],
72
+ name: name,
73
+ iso_code: iso_code,
74
+ last: r['last'],
75
+ buy: r['buy'],
76
+ sell: r['sell'],
77
+ variation: r['variation']
78
+ }
79
+ end
80
+
62
81
  def to_stock r
63
82
  {
64
83
  name: r['name'],
@@ -11,6 +11,7 @@ module HG
11
11
  buy: :buy,
12
12
  sell: :sell,
13
13
  variation: :variation,
14
+ last: :last,
14
15
  daily_factor: 'daily factor'
15
16
  },
16
17
  :'pt-br' => {
@@ -20,6 +21,7 @@ module HG
20
21
  buy: :compra,
21
22
  sell: :venda,
22
23
  variation: 'variação',
24
+ last: 'último',
23
25
  daily_factor: 'fator diário'
24
26
  }
25
27
  }
@@ -1,5 +1,5 @@
1
1
  module HG
2
2
  module Finance
3
- VERSION = "1.0.0"
3
+ VERSION = "1.0.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hg-finance
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hugo Demiglio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-20 00:00:00.000000000 Z
11
+ date: 2018-07-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Get brazilian finance data using HG Finance API.
14
14
  email:
@@ -18,6 +18,7 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - lib/hg/finance.rb
21
+ - lib/hg/finance/crypto_currency.rb
21
22
  - lib/hg/finance/currency.rb
22
23
  - lib/hg/finance/data.rb
23
24
  - lib/hg/finance/locale.rb
@@ -44,7 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
44
45
  version: '0'
45
46
  requirements: []
46
47
  rubyforge_project:
47
- rubygems_version: 2.5.1
48
+ rubygems_version: 2.6.14.1
48
49
  signing_key:
49
50
  specification_version: 4
50
51
  summary: Simple gem to get finance data from HG Finance.