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, 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

#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

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

#websiteObject

Returns the value of attribute website.



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

def website
  @website
end

Class Method Details

.allObject



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

#docObject



33
34
35
# File 'lib/cryptonewbie/crypto.rb', line 33

def doc
 @doc ||= Nokogiri::HTML(open(self.url))
end