Module: Birdwatcher::Concerns::Outputting

Included in:
Birdwatcher::Command, Module
Defined in:
lib/birdwatcher/concerns/outputting.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
# File 'lib/birdwatcher/concerns/outputting.rb', line 4

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#confirm(question) ⇒ Object

Ask the user for confirmation

Waits for the user to answer Yes or No to a question. Useful for making the user confirm destructive actions before executing them.

Examples:

make user confirm division by zero

if confirm("Do you really want divide by zero?")
  0 / 0
end

Parameters:

  • question (String)

    Yes/No question to ask the user



109
110
111
# File 'lib/birdwatcher/concerns/outputting.rb', line 109

def confirm(question)
  HighLine.agree("#{question} (y/n) ")
end

#error(message) ⇒ Object

Output an error message to the console

Formats the message as an error message

Parameters:

  • message (String)

    Message to display



76
77
78
# File 'lib/birdwatcher/concerns/outputting.rb', line 76

def error(message)
  Birdwatcher::Console.instance.error(message)
end

#fatal(message) ⇒ Object

Output a fatal message to the console

Formats the message as a fatal message

Parameters:

  • message (String)

    Message to display



94
95
96
# File 'lib/birdwatcher/concerns/outputting.rb', line 94

def fatal(message)
  Birdwatcher::Console.instance.fatal(message)
end

#info(message) ⇒ Object

Output an informational message to the console

Formats the message as an informational message

Parameters:

  • message (String)

    Message to display



52
53
54
# File 'lib/birdwatcher/concerns/outputting.rb', line 52

def info(message)
  Birdwatcher::Console.instance.info(message)
end

#line_separatorObject

Output a line to the console

Used for consistant spacing and separation between console output



43
44
45
# File 'lib/birdwatcher/concerns/outputting.rb', line 43

def line_separator
  Birdwatcher::Console.instance.line_separator
end

#newlineObject

Output a newline to the console

Used for consistant spacing in console output



36
37
38
# File 'lib/birdwatcher/concerns/outputting.rb', line 36

def newline
  Birdwatcher::Console.instance.newline
end

#output(data) ⇒ Object

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.



17
18
19
# File 'lib/birdwatcher/concerns/outputting.rb', line 17

def output(data)
  Birdwatcher::Console.instance.output(data)
end

#output_formatted(*args) ⇒ Object

Output formatted data to the console

Outputs data with printf formatting.

Examples:

output_formatted("%-15s %s\n", title, description)

Parameters:

  • *args

    Args to be passed



29
30
31
# File 'lib/birdwatcher/concerns/outputting.rb', line 29

def output_formatted(*args)
  Birdwatcher::Console.instance.output_formatted(*args)
end

#task(message, fatal = false, &block) ⇒ Object

Output an informational message to the console that reports when a longer-running task is done.

Examples:

performing a long-running task

task("Performing a long, time consuming task...") do
  long_running_task
end

Parameters:

  • message (String)

    Message to display

  • fatal (Boolean) (defaults to: false)

    OPTIONAL if an exception is raised, treat it as a fatal error

  • block

    The code block to yield



67
68
69
# File 'lib/birdwatcher/concerns/outputting.rb', line 67

def task(message, fatal = false, &block)
  Birdwatcher::Console.instance.task(message, fatal, &block)
end

#warn(message) ⇒ Object

Output a warning message to the console

Formats the message as a warning message

Parameters:

  • message (String)

    Message to display



85
86
87
# File 'lib/birdwatcher/concerns/outputting.rb', line 85

def warn(message)
  Birdwatcher::Console.instance.warn(message)
end