Class: CryptoMarket::Coin

Inherits:
Object
  • Object
show all
Includes:
CryptoMarket
Defined in:
lib/crypto_market/coin.rb

Overview

Crypto Coin belongs to Crypto Currencies Responsible for handling all of the Crypto Coin information

Constant Summary

Constants included from CryptoMarket

VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CryptoMarket

#terminal_table

Constructor Details

#initialize(name, price_usd, price_btc, market_cap_usd, percent_change_24h, last_updated_unix) ⇒ Coin

Instantiate Coin with the attributes below, adds + sign for positive change numbers



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

def initialize(name, price_usd, price_btc, market_cap_usd, percent_change_24h, last_updated_unix)
  @name = name
  @price_usd = price_usd.to_f.round(2)
  @price_btc = price_btc.to_i
  @market_cap_usd = market_cap_usd.to_i
  @percent_change_24h = percent_change_24h.to_i
  @last_updated_unix = last_updated_unix
end

Instance Attribute Details

#last_updated_unixObject

Returns the value of attribute last_updated_unix.



6
7
8
# File 'lib/crypto_market/coin.rb', line 6

def last_updated_unix
  @last_updated_unix
end

#market_cap_usdObject

Returns the value of attribute market_cap_usd.



6
7
8
# File 'lib/crypto_market/coin.rb', line 6

def market_cap_usd
  @market_cap_usd
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/crypto_market/coin.rb', line 6

def name
  @name
end

#percent_change_1hObject

Returns the value of attribute percent_change_1h.



6
7
8
# File 'lib/crypto_market/coin.rb', line 6

def percent_change_1h
  @percent_change_1h
end

#percent_change_24hObject

Returns the value of attribute percent_change_24h.



6
7
8
# File 'lib/crypto_market/coin.rb', line 6

def percent_change_24h
  @percent_change_24h
end

#percent_change_7dObject

Returns the value of attribute percent_change_7d.



6
7
8
# File 'lib/crypto_market/coin.rb', line 6

def percent_change_7d
  @percent_change_7d
end

#price_btcObject

Returns the value of attribute price_btc.



6
7
8
# File 'lib/crypto_market/coin.rb', line 6

def price_btc
  @price_btc
end

#price_usdObject

Returns the value of attribute price_usd.



6
7
8
# File 'lib/crypto_market/coin.rb', line 6

def price_usd
  @price_usd
end

Instance Method Details

#attributesObject

Prints out the coin attributes for the Coin object with terminal-table gem



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/crypto_market/coin.rb', line 20

def attributes
  table = terminal_table do |t|
    t.title = name.upcase
    t.add_row ["Price USD:", "$#{price_usd}"]
    t.add_row ["Price BTC:", "#{price_btc}"]
    t.add_row ["Market Cap USD:", "$#{market_cap_usd}"]
    t.add_row ["Change Last 24h:", "#{percent_change_24h}%"]
    t.add_row ["Last Updated:", "#{Time.at(last_updated_unix.to_i)}"]
    t.style = { all_separators: true, width: 60 }
  end
  puts table
end