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.
Class Method Summary collapse
- .all ⇒ Object
- .find(input) ⇒ Object
- .find_by_name(name) ⇒ Object
- .new_from_index_page(coin) ⇒ Object
Instance Method Summary collapse
-
#initialize(name = nil, price = nil, circulating_supply = nil, change = nil) ⇒ Crypto
constructor
A new instance of Crypto.
Constructor Details
#initialize(name = nil, price = nil, circulating_supply = nil, change = nil) ⇒ Crypto
Returns a new instance of Crypto.
14 15 16 17 18 19 20 |
# File 'lib/cryptonewbie/crypto.rb', line 14 def initialize(name = nil, price = nil, circulating_supply = nil, change = nil) @name = name @price = price @circulating_supply = circulating_supply @change = change @@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 |
Class Method Details
.all ⇒ Object
22 23 24 |
# File 'lib/cryptonewbie/crypto.rb', line 22 def self.all @@all end |
.find(input) ⇒ Object
32 33 34 |
# File 'lib/cryptonewbie/crypto.rb', line 32 def self.find(input) self.all[input - 1] end |
.find_by_name(name) ⇒ Object
26 27 28 29 30 |
# File 'lib/cryptonewbie/crypto.rb', line 26 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 12 |
# File 'lib/cryptonewbie/crypto.rb', line 6 def self.new_from_index_page(coin) self.new( coin.css('a.currency-name-container').text, coin.css('a.price').text, coin.css('td.no-wrap.text-right.circulating-supply a span:nth-child(1)').text, coin.css("td.no-wrap.percent-change").text) end |