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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2658d29f7e1eef424491232ecd47ff7d914ffb493774c06d73d92e881464f911
4
- data.tar.gz: cb3f8a9a04fa098c254b4e7b49b8f7120e1d6c3c86e0bcb6037ba54d2dd847ac
3
+ metadata.gz: dc70d4007c44e40dc3255972fd9f0e8139fb12e2c55b9d59813da1cda45ca441
4
+ data.tar.gz: ae945bc6d4fbc1904e8169d65adfc2b854e226379e4ec8240cb65a1f4d6d74bc
5
5
  SHA512:
6
- metadata.gz: dadf93b8d4a1354daeaa3eae7cd851744e4c3f3e6fc467ebce006b1557191fdfb3acab4d6700a76c6391533a571741c916e205e2e4c71e6dade7ed9f1b00b8b5
7
- data.tar.gz: 2b0d1fc0bdb28cf3c9711a63a0cb3954c9f79e173e33e6cb65afc1a329b432d681c055f7e97602353cffbbf603482171934b9c924cc846ce66693b05d0a7bba5
6
+ metadata.gz: f1d184bcacba5d7893bce09107afca88f8664273a1c4a04c4bd572c6c7edd0aa459a7232266892187770196f42a8042718c8a0a136dc7a37fcd7be96def1b247
7
+ data.tar.gz: 21a9b21482fb393285ac272c503df85a377d2fb7828d77d13669faf114bfac47c4f0c476e7b2d383fe8f9279874c0aebc5ee6c054fa1538e6c54d029d9467b9f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cryptonewbie (0.1.0)
4
+ cryptonewbie (1.0.0)
5
5
  nokogiri
6
6
 
7
7
  GEM
@@ -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 # or Name of the CryptoCurrency you'd like more info on!"
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 5 CryptoCurrencies again!"
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 ""
@@ -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('a.price').text,
10
- coin.css('td.no-wrap.text-right.circulating-supply a span:nth-child(1)').text,
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, price = nil, circulating_supply = nil, change = nil)
15
- @name = name
16
- @price = price
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
@@ -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
- end
20
+
21
+
22
+ end
@@ -1,3 +1,3 @@
1
1
  module Cryptonewbie
2
- VERSION = "0.1.0"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cryptonewbie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - "'Andrew Hong'"