class MoneyExchange::Command
Public Instance Methods
c(str, d='32')
click to toggle source
# File lib/money_exchange/command.rb, line 26 def c(str, d='32') "\e[#{d}m#{str}\e[0m" end
ex(amount, base, *targets)
click to toggle source
# File lib/money_exchange/command.rb, line 6 def ex(amount, base, *targets) results = amount.send("#{base.downcase}_to", *targets.map(&:downcase)) print_in_format(amount, base, targets, results) rescue Exchange::NoCurrencyDataError abort "no exchange data for any of them. see help." rescue abort "you might pass wrong codes. see help." end
print_in_format(amount, base, targets, results)
click to toggle source
# File lib/money_exchange/command.rb, line 16 def print_in_format(amount, base, targets, results) from = "#{base.upcase} #{amount} => " padding = ' ' * from.size head = [from] + [padding] * targets.size head.zip(targets.map(&:upcase), results).map do |h, t, r| h = h.sub(/^\w{3}/) { "#{c $&, 32}" } puts "%s%s %s" % [h, c(t), r] end end
version()
click to toggle source
# File lib/money_exchange/command.rb, line 32 def version puts "MoneyExchange #{MoneyExchange::VERSION} (c) 2013 kyoendo" end