crypto_market 0.1.9 → 0.2.0
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 +4 -4
- data/lib/crypto_market/cli.rb +16 -42
- data/lib/crypto_market/coin.rb +7 -7
- data/lib/crypto_market/currencies.rb +37 -7
- data/lib/crypto_market/version.rb +1 -1
- data/notes.md +0 -32
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 891a2f31514ef916fec0ea21763cc5b2ebe43bd1
|
4
|
+
data.tar.gz: c32bee676d632274f86f9ecf7a797e1e34e52733
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 836369fc1a69e3db413306288f3faa3a12807abf86c95185bb1448272136bd28a814253cc9cd997d4391986ca72b12a85a3c7b8c2ee02874644751bf6a4329d2
|
7
|
+
data.tar.gz: 034dc28b770e5370aaa9335c280b05593892e644b791aca6f87a7b8acb6ba6f4fb992406e5020ce68d06c580499a1ad202e60f630b263f5bf331c966b44e99b7
|
data/lib/crypto_market/cli.rb
CHANGED
@@ -35,12 +35,11 @@ Enter a number to navigate
|
|
35
35
|
def navigation
|
36
36
|
table = terminal_table do |t|
|
37
37
|
t.title = greeting
|
38
|
-
t.add_row [1, '
|
38
|
+
t.add_row [1, 'Get more information about a specific coin']
|
39
39
|
t.add_row [2, 'Sort by price']
|
40
|
-
t.add_row [3, 'Sort by price change']
|
41
|
-
t.add_row [4, '
|
42
|
-
t.
|
43
|
-
t.style = { all_separators: true }
|
40
|
+
t.add_row [3, 'Sort by price change the last 24h']
|
41
|
+
t.add_row [4, 'To exit the program']
|
42
|
+
t.style = { all_separators: true, width: 60 }
|
44
43
|
end
|
45
44
|
puts table
|
46
45
|
enter_input_msg
|
@@ -48,41 +47,38 @@ Enter a number to navigate
|
|
48
47
|
loop do
|
49
48
|
case input
|
50
49
|
when 1
|
51
|
-
|
52
|
-
|
50
|
+
coin_search
|
51
|
+
navigation
|
53
52
|
when 2
|
54
53
|
currencies.print_sorted_prices
|
55
|
-
|
54
|
+
navigation
|
56
55
|
when 3
|
57
56
|
table = terminal_table do |t|
|
58
57
|
t.title = 'Select a number'
|
59
|
-
t.add_row [1, '
|
60
|
-
t.add_row [2, '
|
61
|
-
t.add_row [3, '
|
62
|
-
t.style = { all_separators: true }
|
58
|
+
t.add_row [1, '(+) Changed coins the last 24h']
|
59
|
+
t.add_row [2, '(-) Changed coins the last 24h']
|
60
|
+
t.add_row [3, 'All Changed coins the last 24h']
|
61
|
+
t.style = { all_separators: true, width: 60 }
|
63
62
|
end
|
64
63
|
input = nil
|
65
64
|
until input == 1 || input == 2 || input == 3
|
66
65
|
puts table
|
67
66
|
enter_input_msg
|
68
|
-
input = gets.to_i
|
67
|
+
input = gets.strip.to_i
|
69
68
|
if input == 1
|
70
69
|
currencies.print_sorted_changes('positive')
|
71
|
-
|
70
|
+
navigation
|
72
71
|
elsif input == 2
|
73
72
|
currencies.print_sorted_changes('negative')
|
74
|
-
|
73
|
+
navigation
|
75
74
|
elsif input == 3
|
76
75
|
currencies.print_sorted_changes
|
77
|
-
|
76
|
+
navigation
|
78
77
|
else
|
79
78
|
enter_valid_input_msg
|
80
79
|
end
|
81
80
|
end
|
82
81
|
when 4
|
83
|
-
coin_search
|
84
|
-
nested_menu
|
85
|
-
when 5
|
86
82
|
puts "Goodbye you're now closing Crypto Market!"
|
87
83
|
exit
|
88
84
|
else
|
@@ -93,29 +89,6 @@ Enter a number to navigate
|
|
93
89
|
end
|
94
90
|
end
|
95
91
|
|
96
|
-
# Nested menu that can be accessed inside the main navigation
|
97
|
-
def nested_menu
|
98
|
-
table = terminal_table do |t|
|
99
|
-
t.title = 'Select a number'
|
100
|
-
t.add_row [1, 'To get more information about a specific coin']
|
101
|
-
t.add_row [2, 'To return to the menu']
|
102
|
-
t.style = { all_separators: true }
|
103
|
-
end
|
104
|
-
puts table
|
105
|
-
enter_input_msg
|
106
|
-
input = gets.strip.to_i
|
107
|
-
case input
|
108
|
-
when 1
|
109
|
-
coin_search
|
110
|
-
nested_menu
|
111
|
-
when 2
|
112
|
-
navigation
|
113
|
-
else
|
114
|
-
enter_valid_input_msg
|
115
|
-
nested_menu
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
92
|
# Search for specific name for a coin and return information about it
|
120
93
|
def coin_search
|
121
94
|
currencies.print_coin_names
|
@@ -126,6 +99,7 @@ def coin_search
|
|
126
99
|
coin_search
|
127
100
|
else
|
128
101
|
currencies.find_by_number(input).attributes
|
102
|
+
navigation
|
129
103
|
end
|
130
104
|
end
|
131
105
|
|
data/lib/crypto_market/coin.rb
CHANGED
@@ -9,10 +9,10 @@ class CryptoMarket::Coin
|
|
9
9
|
# Instantiate Coin with the attributes below, adds + sign for positive change numbers
|
10
10
|
def initialize(name, price_usd, price_btc, market_cap_usd, percent_change_24h, last_updated_unix)
|
11
11
|
@name = name
|
12
|
-
@price_usd = price_usd
|
13
|
-
@price_btc = price_btc
|
14
|
-
@market_cap_usd = market_cap_usd
|
15
|
-
@percent_change_24h = percent_change_24h
|
12
|
+
@price_usd = price_usd.to_f.round(2)
|
13
|
+
@price_btc = price_btc.to_i
|
14
|
+
@market_cap_usd = market_cap_usd.to_i
|
15
|
+
@percent_change_24h = percent_change_24h.to_i
|
16
16
|
@last_updated_unix = last_updated_unix
|
17
17
|
end
|
18
18
|
|
@@ -20,9 +20,9 @@ class CryptoMarket::Coin
|
|
20
20
|
def attributes
|
21
21
|
table = terminal_table do |t|
|
22
22
|
t.title = name.upcase
|
23
|
-
t.add_row ["Price USD:", "
|
24
|
-
t.add_row ["Price BTC:", "#{price_btc}
|
25
|
-
t.add_row ["Market Cap USD:", "
|
23
|
+
t.add_row ["Price USD:", "$#{price_usd}"]
|
24
|
+
t.add_row ["Price BTC:", "#{price_btc}"]
|
25
|
+
t.add_row ["Market Cap USD:", "$#{market_cap_usd}"]
|
26
26
|
t.add_row ["Change Last 24h:", "#{percent_change_24h}%"]
|
27
27
|
t.add_row ["Last Updated:", "#{Time.at(last_updated_unix.to_i)}"]
|
28
28
|
t.style = { all_separators: true, width: 60 }
|
@@ -59,11 +59,13 @@ class CryptoMarket::Currencies
|
|
59
59
|
# Prints out the price for all Coin objects with terminal-table gem
|
60
60
|
def print_sorted_prices
|
61
61
|
sort_by_price_usd.each do |coin|
|
62
|
-
|
63
|
-
|
64
|
-
|
62
|
+
unless coin.price_usd == 0
|
63
|
+
table = terminal_table do |t|
|
64
|
+
t.add_row [coin.name, "$#{coin.price_usd}"]
|
65
|
+
t.style = { all_separators: true, width: 60 }
|
66
|
+
end
|
67
|
+
puts table
|
65
68
|
end
|
66
|
-
puts table
|
67
69
|
end
|
68
70
|
end
|
69
71
|
|
@@ -78,14 +80,42 @@ class CryptoMarket::Currencies
|
|
78
80
|
end
|
79
81
|
end
|
80
82
|
|
81
|
-
#
|
83
|
+
# Returns smaller Arrays with coin names and indexes
|
84
|
+
def coin_names_arrays
|
85
|
+
coins.map.with_index do |coin, index|
|
86
|
+
"#{index + 1} #{coin.name}"
|
87
|
+
end.each_slice(coins.size / 6)
|
88
|
+
end
|
89
|
+
|
90
|
+
# To be able to print out coin names in batches
|
91
|
+
# In order for next/break to work I need to keep interactions in this method
|
82
92
|
def print_coin_names
|
83
|
-
|
93
|
+
coin_names_arrays.each do |coin|
|
94
|
+
coin.each do |name|
|
95
|
+
index = name.slice!(/\d+\s/).strip
|
96
|
+
table = terminal_table do |t|
|
97
|
+
t.add_row [index, name]
|
98
|
+
t.style = { all_separators: true, width: 60 }
|
99
|
+
end
|
100
|
+
puts table
|
101
|
+
end
|
84
102
|
table = terminal_table do |t|
|
85
|
-
t.
|
103
|
+
t.title = 'Select a number'
|
104
|
+
t.add_row [1, 'To load more coins']
|
105
|
+
t.add_row [2, 'To select a coin']
|
86
106
|
t.style = { all_separators: true, width: 60 }
|
87
107
|
end
|
88
108
|
puts table
|
109
|
+
input = nil
|
110
|
+
until input == 1 || input == 2
|
111
|
+
input = gets.strip.to_i
|
112
|
+
puts 'Enter a correct number from the list' unless input == 1 || input == 2
|
113
|
+
end
|
114
|
+
if input == 1
|
115
|
+
next
|
116
|
+
elsif input == 2
|
117
|
+
break
|
118
|
+
end
|
89
119
|
end
|
90
120
|
end
|
91
121
|
|
data/notes.md
CHANGED
@@ -2,36 +2,4 @@
|
|
2
2
|
Crypto-Currency Market CLI Gem
|
3
3
|
|
4
4
|
*Price updated every 5 minutes*
|
5
|
-
|
6
5
|
- New Docs: https://coinmarketcap.com/api/
|
7
|
-
|
8
|
-
#### User Interface
|
9
|
-
1. List Crypto-Currencies
|
10
|
-
- Welcome message
|
11
|
-
- Navigation
|
12
|
-
- List all currencies
|
13
|
-
- Sort by pricing
|
14
|
-
- Sort by changed
|
15
|
-
- Get more information about specific coin
|
16
|
-
- Exit
|
17
|
-
2. Pick one to get more information about
|
18
|
-
- Type name of coin you want more information about
|
19
|
-
- Name - name
|
20
|
-
- Price - Price
|
21
|
-
- Change - Past hour price change
|
22
|
-
3. Sort by pricing
|
23
|
-
- Display all coins based on their price (Highest > lowest)
|
24
|
-
4. Sort by changes
|
25
|
-
- Sort by positive changed
|
26
|
-
- See positive changed coins
|
27
|
-
- Sort by negative changed
|
28
|
-
- See negative changed coins
|
29
|
-
- See all
|
30
|
-
- See all coins
|
31
|
-
5. Ask user to perform another action
|
32
|
-
- Loop menu
|
33
|
-
|
34
|
-
Object Relationship
|
35
|
-
|
36
|
-
Rule of thumb:
|
37
|
-
A method that acts on a single object should be an instance method. A method that acts on a group of similar objects should be a class method.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crypto_market
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Ojling
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|