Class: Chid::Commands::Currency::Convert
Constant Summary
Chid::Command::COMMANDS
Instance Attribute Summary
#options
Instance Method Summary
collapse
command, help, #initialize, map_options_with_values, run
Constructor Details
This class inherits a constructor from Chid::Command
Instance Method Details
#amount ⇒ Object
35
36
37
|
# File 'lib/chid/commands/currency/convert.rb', line 35
def amount
options['-amount']&.compact.first.to_f|| 0.0
end
|
#from ⇒ Object
43
44
45
|
# File 'lib/chid/commands/currency/convert.rb', line 43
def from
options['-from']&.compact&.join || 'USD'
end
|
#run ⇒ Object
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
|
#to ⇒ Object
39
40
41
|
# File 'lib/chid/commands/currency/convert.rb', line 39
def to
options['-to']&.compact&.join || 'BRL'
end
|