Class: Decent::ShowHodling

Inherits:
Object
  • Object
show all
Defined in:
lib/decent/command/hodling/show_hodling.rb

Class Method Summary collapse

Class Method Details

.execute(args) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/decent/command/hodling/show_hodling.rb', line 3

def self.execute(args)
  hodlings   = Database[:holdings]
  nickname   = args[1]
  hodling    = hodlings.where(nickname: nickname).first
  balance    = hodling[:balance]
  currency   = hodling[:currency]
  updated_at = hodling[:updated_at]

  exchange_rates  = Database[:exchange_rates]
  exchange_rate   = exchange_rates.where(currency: currency).first
  rate            = exchange_rate[:rate]
  rate_updated_at = exchange_rate[:updated_at]
  value_in_usd    = balance * rate

  puts "#{nickname} has a balance of #{balance} #{currency} as of #{updated_at}."
  puts "At an exchange rate of #{rate} USD, as of #{rate_updated_at}, #{nickname} is worth #{value_in_usd} USD."
end