cryptonewbie 0.1.0 → 1.0.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/Gemfile.lock +1 -1
- data/lib/cryptonewbie/cli.rb +47 -22
- data/lib/cryptonewbie/crypto.rb +27 -11
- data/lib/cryptonewbie/scraper.rb +8 -7
- data/lib/cryptonewbie/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc70d4007c44e40dc3255972fd9f0e8139fb12e2c55b9d59813da1cda45ca441
|
4
|
+
data.tar.gz: ae945bc6d4fbc1904e8169d65adfc2b854e226379e4ec8240cb65a1f4d6d74bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1d184bcacba5d7893bce09107afca88f8664273a1c4a04c4bd572c6c7edd0aa459a7232266892187770196f42a8042718c8a0a136dc7a37fcd7be96def1b247
|
7
|
+
data.tar.gz: 21a9b21482fb393285ac272c503df85a377d2fb7828d77d13669faf114bfac47c4f0c476e7b2d383fe8f9279874c0aebc5ee6c054fa1538e6c54d029d9467b9f
|
data/Gemfile.lock
CHANGED
data/lib/cryptonewbie/cli.rb
CHANGED
@@ -10,52 +10,77 @@ class Cryptonewbie::CLI
|
|
10
10
|
puts "************* Today's Crypto-Market *************"
|
11
11
|
puts ""
|
12
12
|
Cryptonewbie::Crypto.all.each.with_index(1) do |crypto, i|
|
13
|
-
puts "#{i}. #{crypto.name}"
|
13
|
+
puts " #{i}. #{crypto.name}"
|
14
14
|
end
|
15
15
|
puts ""
|
16
16
|
end
|
17
17
|
|
18
|
-
def print_crypto(crypto)
|
19
|
-
puts ""
|
20
|
-
puts "--------- #{crypto.name} ---------"
|
21
|
-
|
22
|
-
puts ""
|
23
|
-
puts "Current Price: #{crypto.price}"
|
24
|
-
puts ""
|
25
|
-
|
26
|
-
puts "Circulating Supply: #{crypto.circulating_supply}"
|
27
|
-
puts ""
|
28
|
-
|
29
|
-
puts "Percent-Change in last 24HR(s): #{crypto.change}"
|
30
|
-
puts ""
|
31
|
-
end
|
32
|
-
|
33
18
|
def start
|
34
19
|
list
|
35
20
|
input = nil
|
36
21
|
while input != "exit"
|
37
|
-
puts "Enter the
|
22
|
+
puts "Enter the (NAME) or (#) of the CryptoCurrency you'd like more info on!"
|
38
23
|
puts ""
|
39
|
-
puts "Enter list to see the Top
|
40
|
-
puts "OR"
|
41
|
-
puts "Enter exit to end the program."
|
24
|
+
puts " Enter list to see the Top-5 again!"
|
25
|
+
puts " OR"
|
26
|
+
puts " Enter exit to end the program."
|
42
27
|
puts ""
|
43
28
|
input = gets.strip
|
44
29
|
|
45
30
|
if input == "list"
|
46
31
|
list
|
47
|
-
elsif input.to_i == 0
|
32
|
+
elsif input.to_i == 0
|
48
33
|
if crypto = Cryptonewbie::Crypto.find_by_name(input)
|
49
34
|
print_crypto(crypto)
|
35
|
+
puts ""
|
36
|
+
puts "Would you like to see another cryptocurrency? ENTER Y or N"
|
37
|
+
input = gets.strip.downcase
|
38
|
+
if input == "y"
|
39
|
+
start
|
40
|
+
else
|
41
|
+
goodbye
|
42
|
+
exit
|
43
|
+
end
|
50
44
|
end
|
51
45
|
elsif input.to_i < 6
|
52
46
|
if crypto = Cryptonewbie::Crypto.find(input.to_i)
|
53
47
|
print_crypto(crypto)
|
48
|
+
puts ""
|
49
|
+
puts "Would you like to see another cryptocurrency? ENTER Y or N"
|
50
|
+
input = gets.strip.downcase
|
51
|
+
if input == "y"
|
52
|
+
start
|
53
|
+
else
|
54
|
+
goodbye
|
55
|
+
exit
|
56
|
+
end
|
54
57
|
end
|
55
|
-
else
|
58
|
+
else
|
56
59
|
list
|
57
60
|
end
|
58
61
|
end
|
62
|
+
goodbye
|
63
|
+
end
|
64
|
+
|
65
|
+
def print_crypto(crypto)
|
66
|
+
puts ""
|
67
|
+
puts "--------- #{crypto.name} ---------"
|
68
|
+
|
69
|
+
puts ""
|
70
|
+
puts "Current Price: $#{crypto.price}"
|
71
|
+
puts ""
|
72
|
+
|
73
|
+
puts "Circulating Supply: #{crypto.circulating_supply}"
|
74
|
+
puts ""
|
75
|
+
|
76
|
+
puts "Percent-Change in last 24HR(s): #{crypto.change}%"
|
77
|
+
puts ""
|
78
|
+
|
79
|
+
puts "Website: #{crypto.website}"
|
80
|
+
puts ""
|
81
|
+
end
|
82
|
+
|
83
|
+
def goodbye
|
59
84
|
puts ""
|
60
85
|
puts "PLEASE RETURN AT ANY TIME TO VIEW THE TOP 5 CRYPTOCURRENCIES!"
|
61
86
|
puts ""
|
data/lib/cryptonewbie/crypto.rb
CHANGED
@@ -1,26 +1,23 @@
|
|
1
1
|
class Cryptonewbie::Crypto
|
2
|
-
attr_accessor :name, :price, :circulating_supply, :change
|
2
|
+
attr_accessor :name, :price, :circulating_supply, :change, :url, :website
|
3
3
|
|
4
4
|
@@all = []
|
5
5
|
|
6
6
|
def self.new_from_index_page(coin)
|
7
7
|
self.new(
|
8
8
|
coin.css('a.currency-name-container').text,
|
9
|
-
coin.css(
|
10
|
-
|
11
|
-
coin.css("td.no-wrap.percent-change").text)
|
9
|
+
"https://coinmarketcap.com#{coin.css("a").attribute("href").text}"
|
10
|
+
)
|
12
11
|
end
|
13
12
|
|
14
|
-
def initialize(name = nil,
|
15
|
-
@name = name
|
16
|
-
@
|
17
|
-
@circulating_supply = circulating_supply
|
18
|
-
@change = change
|
13
|
+
def initialize(name = nil, url = nil)
|
14
|
+
@name = name
|
15
|
+
@url = url
|
19
16
|
@@all << self
|
20
17
|
end
|
21
18
|
|
22
|
-
def self.all
|
23
|
-
@@all
|
19
|
+
def self.all
|
20
|
+
@@all
|
24
21
|
end
|
25
22
|
|
26
23
|
def self.find_by_name(name)
|
@@ -33,5 +30,24 @@ class Cryptonewbie::Crypto
|
|
33
30
|
self.all[input - 1]
|
34
31
|
end
|
35
32
|
|
33
|
+
def doc
|
34
|
+
@doc ||= Nokogiri::HTML(open(self.url))
|
35
|
+
end
|
36
|
+
|
37
|
+
def price
|
38
|
+
@price ||= doc.css("span#quote_price span.text-large2").text
|
39
|
+
end
|
40
|
+
|
41
|
+
def circulating_supply
|
42
|
+
@circulating_supply ||= doc.css("div.col-sm-8.col-sm-push-4 div:nth-child(4) span").text.strip
|
43
|
+
end
|
44
|
+
|
45
|
+
def change
|
46
|
+
@change ||= doc.css("div.col-xs-6.col-sm-8.col-md-4.text-left span:nth-child(2) span").text
|
47
|
+
end
|
48
|
+
|
49
|
+
def website
|
50
|
+
@website ||= doc.css("ul.list-unstyled li:nth-child(1) a").attribute("href").text
|
51
|
+
end
|
36
52
|
|
37
53
|
end
|
data/lib/cryptonewbie/scraper.rb
CHANGED
@@ -1,21 +1,22 @@
|
|
1
|
-
class Cryptonewbie::Scraper
|
1
|
+
class Cryptonewbie::Scraper
|
2
2
|
|
3
|
-
def get_page
|
3
|
+
def get_page
|
4
4
|
Nokogiri::HTML(open("https://coinmarketcap.com"))
|
5
5
|
end
|
6
6
|
|
7
|
-
def get_cryptos
|
7
|
+
def get_cryptos
|
8
8
|
table = self.get_page.at('table#currencies')
|
9
9
|
content = table.css('tbody')
|
10
10
|
rows = content.css('tr')
|
11
11
|
end
|
12
12
|
|
13
|
-
def make_cryptos
|
13
|
+
def make_cryptos
|
14
14
|
self.get_cryptos.collect do |coin|
|
15
15
|
if coin.css('td.text-center').text.strip.to_i < 6
|
16
16
|
Cryptonewbie::Crypto.new_from_index_page(coin)
|
17
17
|
end
|
18
|
-
end
|
18
|
+
end.compact
|
19
19
|
end
|
20
|
-
|
21
|
-
|
20
|
+
|
21
|
+
|
22
|
+
end
|
data/lib/cryptonewbie/version.rb
CHANGED