module Birdwatcher::Concerns::Outputting

Public Class Methods

included(base) click to toggle source
# File lib/birdwatcher/concerns/outputting.rb, line 4
def self.included(base)
  base.extend(ClassMethods)
end

Public Instance Methods

confirm(question) click to toggle source

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
error(message) click to toggle source

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
fatal(message) click to toggle source

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
info(message) click to toggle source

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
line_separator() click to toggle source

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
newline() click to toggle source

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) click to toggle source

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(*args) click to toggle source

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
task(message, fatal = false, &block) click to toggle source

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
warn(message) click to toggle source

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