Class: Satoshi::Coin

Inherits:
Object
  • Object
show all
Defined in:
lib/satoshi/coin.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#btc_market_capObject

Returns the value of attribute btc_market_cap.



2
3
4
# File 'lib/satoshi/coin.rb', line 2

def btc_market_cap
  @btc_market_cap
end

#btc_priceObject

Returns the value of attribute btc_price.



2
3
4
# File 'lib/satoshi/coin.rb', line 2

def btc_price
  @btc_price
end

#circulating_supply_btcObject

Returns the value of attribute circulating_supply_btc.



2
3
4
# File 'lib/satoshi/coin.rb', line 2

def circulating_supply_btc
  @circulating_supply_btc
end

#indexObject

Returns the value of attribute index.



2
3
4
# File 'lib/satoshi/coin.rb', line 2

def index
  @index
end

Returns the value of attribute info_link.



2
3
4
# File 'lib/satoshi/coin.rb', line 2

def info_link
  @info_link
end

#last_priceObject

Returns the value of attribute last_price.



2
3
4
# File 'lib/satoshi/coin.rb', line 2

def last_price
  @last_price
end

#max_supplyObject

Returns the value of attribute max_supply.



2
3
4
# File 'lib/satoshi/coin.rb', line 2

def max_supply
  @max_supply
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/satoshi/coin.rb', line 2

def name
  @name
end

#percent_changeObject

Returns the value of attribute percent_change.



2
3
4
# File 'lib/satoshi/coin.rb', line 2

def percent_change
  @percent_change
end

#tickerObject

Returns the value of attribute ticker.



2
3
4
# File 'lib/satoshi/coin.rb', line 2

def ticker
  @ticker
end

#usd_market_capObject

Returns the value of attribute usd_market_cap.



2
3
4
# File 'lib/satoshi/coin.rb', line 2

def usd_market_cap
  @usd_market_cap
end

#usd_priceObject

Returns the value of attribute usd_price.



2
3
4
# File 'lib/satoshi/coin.rb', line 2

def usd_price
  @usd_price
end

#volume_btc_24hrObject

Returns the value of attribute volume_btc_24hr.



2
3
4
# File 'lib/satoshi/coin.rb', line 2

def volume_btc_24hr
  @volume_btc_24hr
end

#volume_usd_24hrObject

Returns the value of attribute volume_usd_24hr.



2
3
4
# File 'lib/satoshi/coin.rb', line 2

def volume_usd_24hr
  @volume_usd_24hr
end

Class Method Details

.allObject



24
25
26
# File 'lib/satoshi/coin.rb', line 24

def self.all
  @@all
end

.create(name, link, index, price) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/satoshi/coin.rb', line 9

def self.create(name, link, index, price)
  coin = self.new
  coin.name = name
  coin.info_link = link
  coin.index = index
  coin.usd_price = price
  coin.last_price = price.to_f
  coin.save
  self.sort_all_by_index
end

.find_by_name(name) ⇒ Object



48
49
50
# File 'lib/satoshi/coin.rb', line 48

def self.find_by_name(name)
  self.all.find {|coin| coin.name.downcase == name.downcase}
end

.sort_all_by_indexObject



20
21
22
# File 'lib/satoshi/coin.rb', line 20

def self.sort_all_by_index
  self.all.sort_by { |coin| coin.index}
end

Instance Method Details

#display_infoObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/satoshi/coin.rb', line 35

def display_info
    puts "-------------------------"
    puts "#{self.name} = $#{self.usd_price}"
    puts "Price In btc = #{self.btc_price}"
    puts "Ticker = #{self.ticker}"
    puts "24hr Percent Change = #{self.percent_change}%"
    puts "Market Cap = $#{self.usd_market_cap} = #{self.btc_market_cap} btc"
    puts "24hr Volume = $#{self.volume_usd_24hr} = #{self.volume_btc_24hr} btc"
    puts "Circulating Supply = #{self.circulating_supply_btc}"
    puts "Max Supply = #{self.max_supply}" if self.max_supply
    puts "-------------------------"
end

#load_info(info_hash) ⇒ Object



28
29
30
31
32
33
# File 'lib/satoshi/coin.rb', line 28

def load_info(info_hash)
  info_hash.each {|key, value|
      self.send("#{key}=",value)
   }
   display_info
end

#saveObject



5
6
7
# File 'lib/satoshi/coin.rb', line 5

def save
  self.class.all << self
end