Module: Ego::Printer

Defined in:
lib/ego/printer.rb

Overview

Utility methods for writing output with formatting.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.errs(*message) ⇒ nil

Writes the given message(s) to $stderr, appending a newline if not already included.

Parameters:

  • *message (Object, ...)

    message(s) to write

Returns:

  • (nil)


94
95
96
# File 'lib/ego/printer.rb', line 94

def errs(*message)
  warn(*message)
end

.puts(*message) ⇒ nil

Writes the given message(s) to $stdout, appending a newline if not already included.

Parameters:

  • *message (Object, ...)

    message(s) to write

Returns:

  • (nil)


85
86
87
# File 'lib/ego/printer.rb', line 85

def puts(*message)
  $stdout.puts(*message)
end

Instance Method Details

#alert(message, *replacements) ⇒ nil

Write stylized message to $stderr indicating an error or warning message.

Examples:

name = 'world'
robot.alert 'Hello, %s.', name
# => "Hello, world."

Parameters:

  • message (Object)

    message to write

  • *replacements (Object, ...)

    printf-style replacements

Returns:

  • (nil)


49
50
51
# File 'lib/ego/printer.rb', line 49

def alert(message, *replacements)
  errs format(message, *replacements).light_red
end

#debug(message, *replacements) ⇒ nil

Write stylized message to $stderr indicating a debugging message.

Plug-ins may use this method to provide extra information when the --verbose flag is supplied at the command-line.

Examples:

result = 'output'
robot.debug 'Result: %s.', result
# => "Result: output"

Parameters:

  • message (Object)

    message to write

  • *replacements (Object, ...)

    printf-style replacements

Returns:

  • (nil)


66
67
68
# File 'lib/ego/printer.rb', line 66

def debug(message, *replacements)
  errs format(message, *replacements) if verbose?
end

#emote(message) ⇒ nil

Write stylized message to $stdout indicating an emote.

Plug-ins may use this method to indicate what the robot is doing.

Examples:

robot.emote 'runs away'
# => "*runs away*"

Parameters:

  • message (Object)

    message to write

Returns:

  • (nil)


34
35
36
# File 'lib/ego/printer.rb', line 34

def emote(message)
  puts "*#{message}*".magenta
end

#say(message, *replacements) ⇒ nil

Write stylized message to $stdout indicating speech.

Examples:

name = 'world'
robot.say 'Hello, %s.', name
# => "Hello, world."

Parameters:

  • message (Object)

    message to write

  • *replacements (Object, ...)

    printf-style replacements

Returns:

  • (nil)


20
21
22
# File 'lib/ego/printer.rb', line 20

def say(message, *replacements)
  puts format(message, *replacements).bold
end

#verbose?false

Whether to print debugging messages. Can be overridden by classes that include Printer.

Returns:

  • (false)

    should print debugging messages?



74
75
76
# File 'lib/ego/printer.rb', line 74

def verbose?
  false
end