summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormokha <mokha@cisco.com>2018-03-06 19:16:32 -0700
committermokha <mokha@cisco.com>2018-03-06 19:16:32 -0700
commit46debca698921e0a9e565df12080eca6bfa75166 (patch)
tree60b94bbf9da90f686e1148c5848c04fdf06d3661 /lib
parent6c5d043ea86bcae39aa806e53625f55bd5a6bf03 (diff)
add class option for colour.
Diffstat (limited to 'lib')
-rw-r--r--lib/xsay.rb11
1 files changed, 4 insertions, 7 deletions
diff --git a/lib/xsay.rb b/lib/xsay.rb
index 00f769b..d19c2d4 100644
--- a/lib/xsay.rb
+++ b/lib/xsay.rb
@@ -5,6 +5,7 @@ require "colorize"
module Xsay
class CLI < Thor
ANIMALS=Dir[File.expand_path("xsay/templates/*.template", File.dirname(__FILE__))]
+ class_option :colour, default: :default, required: false
ANIMALS.each do |filename|
animal = File.basename(filename).split(".")[0]
@@ -24,17 +25,13 @@ module Xsay
desc "random <message>", "xsay random hello"
def random(*args)
- render(args, IO.read(ANIMALS.shuffle.sample), colour: String.colors.sample)
- end
-
- desc "rainbow <message>", "xsay rainbow hello world"
- def rainbow(*args)
- render(args, IO.read(ANIMALS.shuffle.sample), colour: :rainbow)
+ random_color = (String.colors + [:rainbow]).sample
+ render(args, IO.read(ANIMALS.shuffle.sample), colour: random_color)
end
private
- def render(message, template, colour: :default)
+ def render(message, template, colour: options[:colour].to_sym)
message = message.join(' ') if message.respond_to?(:join)
line_break = "-" * message.length
result = <<-MESSAGE