Class: Cryptonewbie::Crypto
- Inherits:
-
Object
- Object
- Cryptonewbie::Crypto
- Defined in:
- lib/cryptonewbie/crypto.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#change ⇒ Object
Returns the value of attribute change.
-
#circulating_supply ⇒ Object
Returns the value of attribute circulating_supply.
-
#name ⇒ Object
Returns the value of attribute name.
-
#price ⇒ Object
Returns the value of attribute price.
-
#url ⇒ Object
Returns the value of attribute url.
-
#website ⇒ Object
Returns the value of attribute website.
Class Method Summary collapse
- .all ⇒ Object
- .find(input) ⇒ Object
- .find_by_name(name) ⇒ Object
- .new_from_index_page(coin) ⇒ Object
Instance Method Summary collapse
- #doc ⇒ Object
-
#initialize(name = nil, url = nil) ⇒ Crypto
constructor
A new instance of Crypto.
Constructor Details
#initialize(name = nil, url = nil) ⇒ Crypto
Returns a new instance of Crypto.
13 14 15 16 17 |
# File 'lib/cryptonewbie/crypto.rb', line 13 def initialize(name = nil, url = nil) @name = name @url = url @@all << self end |
Instance Attribute Details
#change ⇒ Object
Returns the value of attribute change.
2 3 4 |
# File 'lib/cryptonewbie/crypto.rb', line 2 def change @change end |
#circulating_supply ⇒ Object
Returns the value of attribute circulating_supply.
2 3 4 |
# File 'lib/cryptonewbie/crypto.rb', line 2 def circulating_supply @circulating_supply end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/cryptonewbie/crypto.rb', line 2 def name @name end |
#price ⇒ Object
Returns the value of attribute price.
2 3 4 |
# File 'lib/cryptonewbie/crypto.rb', line 2 def price @price end |
#url ⇒ Object
Returns the value of attribute url.
2 3 4 |
# File 'lib/cryptonewbie/crypto.rb', line 2 def url @url end |
#website ⇒ Object
Returns the value of attribute website.
2 3 4 |
# File 'lib/cryptonewbie/crypto.rb', line 2 def website @website end |
Class Method Details
.all ⇒ Object
19 20 21 |
# File 'lib/cryptonewbie/crypto.rb', line 19 def self.all @@all end |
.find(input) ⇒ Object
29 30 31 |
# File 'lib/cryptonewbie/crypto.rb', line 29 def self.find(input) self.all[input - 1] end |
.find_by_name(name) ⇒ Object
23 24 25 26 27 |
# File 'lib/cryptonewbie/crypto.rb', line 23 def self.find_by_name(name) self.all.detect do |crypto| crypto.name.downcase.strip == name.downcase.strip end end |
.new_from_index_page(coin) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/cryptonewbie/crypto.rb', line 6 def self.new_from_index_page(coin) self.new( coin.css('a.currency-name-container').text, "https://coinmarketcap.com#{coin.css("a").attribute("href").text}" ) end |
Instance Method Details
#doc ⇒ Object
33 34 35 |
# File 'lib/cryptonewbie/crypto.rb', line 33 def doc @doc ||= Nokogiri::HTML(open(self.url)) end |