class Chg::CLI
CLI
interface
Constants
- MissingKey
Attributes
key[R]
Public Class Methods
new(key)
click to toggle source
# File lib/chg/cli.rb, line 11 def initialize(key) @key = key end
Public Instance Methods
change(from, to, amount)
click to toggle source
# File lib/chg/cli.rb, line 19 def change(from, to, amount) changed = amount * rate(from, to) "#{amount} #{from.upcase} = #{changed} #{to.upcase}" end
rate(from, to)
click to toggle source
# File lib/chg/cli.rb, line 24 def rate(from, to) raise MissingKey unless key xchg = Alphavantage::Exchange.new(from: from, to: to, key: key).now xchg.exchange_rate.to_f end
usage()
click to toggle source
# File lib/chg/cli.rb, line 15 def usage "Usage: #{program} <from> <to> [amount = 1]" end
Private Instance Methods
program()
click to toggle source
# File lib/chg/cli.rb, line 33 def program $PROGRAM_NAME.sub(%r{.*/}, '') end