Class: Chid::Commands::Currency::Convert

Inherits:
Chid::Command show all
Defined in:
lib/chid/commands/currency/convert.rb

Constant Summary

Constants inherited from Chid::Command

Chid::Command::COMMANDS

Instance Attribute Summary

Attributes inherited from Chid::Command

#options

Instance Method Summary collapse

Methods inherited from Chid::Command

command, help, #initialize, map_options_with_values, run

Constructor Details

This class inherits a constructor from Chid::Command

Instance Method Details

#amountObject



35
36
37
# File 'lib/chid/commands/currency/convert.rb', line 35

def amount
  options['-amount']&.compact.first.to_f|| 0.0
end

#fromObject



43
44
45
# File 'lib/chid/commands/currency/convert.rb', line 43

def from
  options['-from']&.compact&.join || 'USD'
end

#runObject



30
31
32
33
# File 'lib/chid/commands/currency/convert.rb', line 30

def run
  currency = CurrencyApi.convert(amount: amount, to: to, from: from)
  puts "Converted amount: #{amount} #{from} is #{currency} #{to}"
end

#toObject



39
40
41
# File 'lib/chid/commands/currency/convert.rb', line 39

def to
  options['-to']&.compact&.join || 'BRL'
end