Class: CryptoMarket::Coin
- Inherits:
-
Object
- Object
- CryptoMarket::Coin
- 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
Instance Attribute Summary collapse
-
#last_updated_unix ⇒ Object
Returns the value of attribute last_updated_unix.
-
#market_cap_usd ⇒ Object
Returns the value of attribute market_cap_usd.
-
#name ⇒ Object
Returns the value of attribute name.
-
#percent_change_1h ⇒ Object
Returns the value of attribute percent_change_1h.
-
#percent_change_24h ⇒ Object
Returns the value of attribute percent_change_24h.
-
#percent_change_7d ⇒ Object
Returns the value of attribute percent_change_7d.
-
#price_btc ⇒ Object
Returns the value of attribute price_btc.
-
#price_usd ⇒ Object
Returns the value of attribute price_usd.
Instance Method Summary collapse
-
#attributes ⇒ Object
Prints out the coin attributes for the Coin object with terminal-table gem.
-
#initialize(name, price_usd, price_btc, market_cap_usd, percent_change_24h, last_updated_unix) ⇒ Coin
constructor
Instantiate Coin with the attributes below, adds + sign for positive change numbers.
Methods included from CryptoMarket
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_unix ⇒ Object
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_usd ⇒ Object
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 |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/crypto_market/coin.rb', line 6 def name @name end |
#percent_change_1h ⇒ Object
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_24h ⇒ Object
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_7d ⇒ Object
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_btc ⇒ Object
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_usd ⇒ Object
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
#attributes ⇒ Object
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 |