Class: Cryptonewbie::Crypto

Inherits:
Object
  • Object
show all
Defined in:
lib/cryptonewbie/crypto.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#changeObject

Returns the value of attribute change.



2
3
4
# File 'lib/cryptonewbie/crypto.rb', line 2

def change
  @change
end

#circulating_supplyObject

Returns the value of attribute circulating_supply.



2
3
4
# File 'lib/cryptonewbie/crypto.rb', line 2

def circulating_supply
  @circulating_supply
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/cryptonewbie/crypto.rb', line 2

def name
  @name
end

#priceObject

Returns the value of attribute price.



2
3
4
# File 'lib/cryptonewbie/crypto.rb', line 2

def price
  @price
end

Class Method Details

.allObject



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