module Birdwatcher::Concerns::Outputting
Public Class Methods
# File lib/birdwatcher/concerns/outputting.rb, line 4 def self.included(base) base.extend(ClassMethods) end
Public Instance Methods
Ask the user for confirmation
@param question [String] Yes/No question to ask the user
Waits for the user to answer Yes or No to a question. Useful for making the user confirm destructive actions before executing them.
@example make user confirm division by zero
if confirm("Do you really want divide by zero?") 0 / 0 end
# File lib/birdwatcher/concerns/outputting.rb, line 109 def confirm(question) Birdwatcher::Console.instance.confirm(question) end
Output an error message to the console
@param message [String] Message to display
Formats the message as an error message
# File lib/birdwatcher/concerns/outputting.rb, line 76 def error(message) Birdwatcher::Console.instance.error(message) end
Output a fatal message to the console
@param message [String] Message to display
Formats the message as a fatal message
# File lib/birdwatcher/concerns/outputting.rb, line 94 def fatal(message) Birdwatcher::Console.instance.fatal(message) end
Output an informational message to the console
@param message [String] Message to display
Formats the message as an informational message
# File lib/birdwatcher/concerns/outputting.rb, line 52 def info(message) Birdwatcher::Console.instance.info(message) end
Output a line to the console
Used for consistant spacing and separation between console output
# File lib/birdwatcher/concerns/outputting.rb, line 43 def line_separator Birdwatcher::Console.instance.line_separator end
Output a newline to the console
Used for consistant spacing in console output
# File lib/birdwatcher/concerns/outputting.rb, line 36 def newline Birdwatcher::Console.instance.newline end
Output data to the console
Simply outputs the given data to the console.
For more convenient and consistant outputting, see the {info}, {task}, {error}, {warn} and {fatal} methods.
# File lib/birdwatcher/concerns/outputting.rb, line 17 def output(data) Birdwatcher::Console.instance.output(data) end
Output formatted data to the console
Outputs data with printf
formatting.
@example
output_formatted("%-15s %s\n", title, description)
@param *args Args to be passed
# File lib/birdwatcher/concerns/outputting.rb, line 29 def output_formatted(*args) Birdwatcher::Console.instance.output_formatted(*args) end
Output an informational message to the console that reports when a longer-running task is done.
@param message [String] Message to display @param fatal [Boolean] OPTIONAL if an exception is raised, treat it as a fatal error @param block The code block to yield
@example performing a long-running task
task("Performing a long, time consuming task...") do long_running_task end
# File lib/birdwatcher/concerns/outputting.rb, line 67 def task(message, fatal = false, &block) Birdwatcher::Console.instance.task(message, fatal, &block) end
Output a warning message to the console
@param message [String] Message to display
Formats the message as a warning message
# File lib/birdwatcher/concerns/outputting.rb, line 85 def warn(message) Birdwatcher::Console.instance.warn(message) end