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 +4 -4
- data/Makefile +18 -0
- data/README.md +2 -0
- data/exe/capwatch +2 -1
- data/lib/capwatch.rb +29 -29
- data/lib/capwatch/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80a8d3dc5f7e4139d0430bea78b74f45c9a03f19
|
4
|
+
data.tar.gz: edc504b6fc384ec132dad1759313c3a9e3fb8b1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
data/exe/capwatch
CHANGED
@@ -4,7 +4,8 @@ require 'capwatch'
|
|
4
4
|
include Capwatch
|
5
5
|
|
6
6
|
options = CLI.parse(ARGV)
|
7
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
89
|
+
footer = [
|
84
90
|
'',
|
85
91
|
'',
|
86
92
|
'',
|
@@ -93,12 +99,12 @@ module Capwatch
|
|
93
99
|
a_7d
|
94
100
|
]
|
95
101
|
|
96
|
-
|
102
|
+
table.sort_by! { |a| -a[6].to_f } # DIST (%)
|
97
103
|
|
98
104
|
{}
|
99
105
|
.merge(title: title)
|
100
|
-
.merge(
|
101
|
-
.merge(
|
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
|
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[:
|
159
|
-
x[2] =
|
160
|
-
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[:
|
169
|
-
hash[:
|
170
|
-
hash[:
|
171
|
-
hash[:
|
172
|
-
hash[:
|
173
|
-
hash[:
|
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[:
|
201
|
+
hash[:table].each do |x|
|
202
202
|
t << x
|
203
203
|
end
|
204
204
|
t.add_separator
|
205
|
-
t.add_row hash[:
|
205
|
+
t.add_row hash[:footer]
|
206
206
|
end
|
207
207
|
|
208
208
|
table
|
data/lib/capwatch/version.rb
CHANGED
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.
|
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
|