capwatch 0.1.0 → 0.1.10

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
  SHA1:
3
- metadata.gz: a934d8a761e346d0ab2dcb852fe541d32c07954f
4
- data.tar.gz: 8f054359548fbfa45509f2e51b77b9494dc6442d
3
+ metadata.gz: 80a8d3dc5f7e4139d0430bea78b74f45c9a03f19
4
+ data.tar.gz: edc504b6fc384ec132dad1759313c3a9e3fb8b1b
5
5
  SHA512:
6
- metadata.gz: 99e5575e7dd8128827d981708964e2196a3fbe28d7d00346e55a46bc328b8cc9b05871f3ff8612d1303e60af2aa0ee69b977aca670627af47b6e8263da9a7918
7
- data.tar.gz: 4da02578277a26144ce9bf0110607ece20cb215840f65415f0aa8937d4e2ac738a1a53e158370c3578126d5647001ae31e8d06a0f4a759d6da84768f8d645cb5
6
+ metadata.gz: 0aa7b3ef4ac92cd7290efce4ec932c2223ed618e6f3ce0e3a7f76049ffc734d13539d25460df5e59d10724f0ad440db450c0f089fc5790f61aba294df195ab18
7
+ data.tar.gz: b4d5f1b942bec8b20a59f71d41a3a87de3457538649ff9c37f08b09612299983284bffa0aa95eb1dba0ee56a58025b1d72b9c74678fc35714e34c24d36a16d65
data/Makefile ADDED
@@ -0,0 +1,18 @@
1
+ all: build install
2
+
3
+ build:
4
+ gem build capwatch.gemspec
5
+
6
+ install:
7
+ gem install capwatch-*.gem
8
+ rm capwatch-*.gem
9
+
10
+ clean:
11
+ gem uninstall -x capwatch
12
+
13
+ test:
14
+ bundle exec rspec
15
+
16
+ push: build
17
+ gem push capwatch-*.gem
18
+ rm capwatch-*.gem
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Watch you cryptoportfolio in a console
4
4
 
5
+ ![Demo](https://i.imgur.com/XioyQQo.png)
6
+
5
7
  ## Installation
6
8
 
7
9
  $ gem install capwatch
data/exe/capwatch CHANGED
@@ -4,7 +4,8 @@ require 'capwatch'
4
4
  include Capwatch
5
5
 
6
6
  options = CLI.parse(ARGV)
7
- fund = JSON.parse(File.open(ARGV[0] || File.expand_path('~/.capwatch')).read)
7
+ capwatch_file = File.expand_path('~/.capwatch')
8
+ fund = JSON.parse(File.open(capwatch_file).read)
8
9
 
9
10
  loop do
10
11
  table = Calculator.fund_hash(fund, CoinMarketCap.fetch)
data/lib/capwatch.rb CHANGED
@@ -1,17 +1,23 @@
1
- require 'colorize'
2
- require 'terminal-table'
3
-
4
- require 'capwatch/version'
5
-
6
1
  require 'json'
7
2
  require 'optparse'
8
3
  require 'ostruct'
9
4
  require 'net/http'
10
5
 
6
+ require 'colorize'
7
+ require 'terminal-table'
8
+
9
+ require 'capwatch/version'
10
+
11
11
  module Capwatch
12
+ class CoinMarketCap
13
+ def self.fetch
14
+ JSON.parse(Net::HTTP.get(URI('http://api.coinmarketcap.com/v1/ticker/')))
15
+ end
16
+ end
17
+
12
18
  class Calculator
13
19
  def self.fund_hash(fund, coinmarketcap_json)
14
- table_array = []
20
+ table = []
15
21
 
16
22
  title = fund['name']
17
23
  symbols = fund['symbols']
@@ -54,7 +60,7 @@ module Capwatch
54
60
  percent_change_1h = x['percent_change_1h'].to_f || 0
55
61
  percent_change_24h = x['percent_change_24h'].to_f || 0
56
62
  percent_change_7d = x['percent_change_7d'].to_f || 0
57
- table_array << [
63
+ table << [
58
64
  asset_name,
59
65
  quant_value,
60
66
  price,
@@ -80,7 +86,7 @@ module Capwatch
80
86
  sum + n['percent_change_7d'].to_f * distribution_hash[n['symbol']].to_f
81
87
  end
82
88
 
83
- footer_row = [
89
+ footer = [
84
90
  '',
85
91
  '',
86
92
  '',
@@ -93,12 +99,12 @@ module Capwatch
93
99
  a_7d
94
100
  ]
95
101
 
96
- table_array.sort_by! { |a| -a[6].to_f } # DIST (%)
102
+ table.sort_by! { |a| -a[6].to_f } # DIST (%)
97
103
 
98
104
  {}
99
105
  .merge(title: title)
100
- .merge(table_array: table_array)
101
- .merge(footer_row: footer_row)
106
+ .merge(table: table)
107
+ .merge(footer: footer)
102
108
  end
103
109
  end
104
110
 
@@ -116,14 +122,8 @@ module Capwatch
116
122
  end
117
123
  end
118
124
 
119
- class CoinMarketCap
120
- def self.fetch
121
- JSON.parse(Net::HTTP.get(URI('http://api.coinmarketcap.com/v1/ticker/')))
122
- end
123
- end
124
-
125
125
  module ConsoleFormatter
126
- def fmt(n)
126
+ def format_usd(n)
127
127
  '$' + n.round(2).to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
128
128
  end
129
129
 
@@ -155,9 +155,9 @@ module Capwatch
155
155
  extend ConsoleFormatter
156
156
 
157
157
  def self.colorize_table(hash)
158
- hash[:table_array].each do |x|
159
- x[2] = fmt(x[2])
160
- x[3] = fmt(x[3])
158
+ hash[:table].each do |x|
159
+ x[2] = format_usd(x[2])
160
+ x[3] = format_usd(x[3])
161
161
  x[4] = format_btc(x[4])
162
162
  x[5] = format_eth(x[5])
163
163
  x[6] = format_percent(x[6])
@@ -165,12 +165,12 @@ module Capwatch
165
165
  x[8] = condition_color(format_percent(x[8]))
166
166
  x[9] = condition_color(format_percent(x[9]))
167
167
  end
168
- hash[:footer_row][3] = fmt(hash[:footer_row][3])
169
- hash[:footer_row][4] = format_btc(hash[:footer_row][4])
170
- hash[:footer_row][5] = format_eth(hash[:footer_row][5])
171
- hash[:footer_row][7] = condition_color(format_percent(hash[:footer_row][7]))
172
- hash[:footer_row][8] = condition_color(format_percent(hash[:footer_row][8]))
173
- hash[:footer_row][9] = condition_color(format_percent(hash[:footer_row][9]))
168
+ hash[:footer][3] = format_usd(hash[:footer][3])
169
+ hash[:footer][4] = format_btc(hash[:footer][4])
170
+ hash[:footer][5] = format_eth(hash[:footer][5])
171
+ hash[:footer][7] = condition_color(format_percent(hash[:footer][7]))
172
+ hash[:footer][8] = condition_color(format_percent(hash[:footer][8]))
173
+ hash[:footer][9] = condition_color(format_percent(hash[:footer][9]))
174
174
  hash
175
175
  end
176
176
 
@@ -198,11 +198,11 @@ module Capwatch
198
198
  '%(24H)',
199
199
  '%(7D)'
200
200
  ]
201
- hash[:table_array].each do |x|
201
+ hash[:table].each do |x|
202
202
  t << x
203
203
  end
204
204
  t.add_separator
205
- t.add_row hash[:footer_row]
205
+ t.add_row hash[:footer]
206
206
  end
207
207
 
208
208
  table
@@ -1,3 +1,3 @@
1
1
  module Capwatch
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.10'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capwatch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Bugaiov
@@ -93,6 +93,7 @@ files:
93
93
  - ".travis.yml"
94
94
  - Gemfile
95
95
  - LICENSE.txt
96
+ - Makefile
96
97
  - README.md
97
98
  - Rakefile
98
99
  - bin/console