Class: Printer
- Inherits:
-
Object
- Object
- Printer
- Defined in:
- lib/printer.rb
Overview
Greg Seitz
Copyright 2013, eBay Inc.
All rights reserved.
http://www.ebay.com
Instance Attribute Summary collapse
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdin ⇒ Object
readonly
Returns the value of attribute stdin.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Instance Method Summary collapse
- #color(string, *colors) ⇒ Object
-
#color? ⇒ Boolean
Should colored output be used? Only on TTY.
-
#error(message) ⇒ Object
Print an error message.
-
#fatal(message) ⇒ Object
Print a message describing a fatal error.
- #highline ⇒ Object
-
#initialize(stdout = STDOUT, stderr = STDERR, stdin = STDIN) ⇒ Printer
constructor
A new instance of Printer.
-
#msg(message) ⇒ Object
(also: #info)
Prints a message to stdout.
-
#warn(message) ⇒ Object
Print a warning message.
Constructor Details
#initialize(stdout = STDOUT, stderr = STDERR, stdin = STDIN) ⇒ Printer
Returns a new instance of Printer.
13 14 15 |
# File 'lib/printer.rb', line 13 def initialize(stdout=STDOUT, stderr=STDERR, stdin=STDIN) @stdout, @stderr, @stdin = stdout, stderr, stdin end |
Instance Attribute Details
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
10 11 12 |
# File 'lib/printer.rb', line 10 def stderr @stderr end |
#stdin ⇒ Object (readonly)
Returns the value of attribute stdin.
11 12 13 |
# File 'lib/printer.rb', line 11 def stdin @stdin end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
9 10 11 |
# File 'lib/printer.rb', line 9 def stdout @stdout end |
Instance Method Details
#color(string, *colors) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/printer.rb', line 48 def color(string, *colors) if color? highline.color(string, *colors) else string end end |
#color? ⇒ Boolean
Should colored output be used? Only on TTY
57 58 59 |
# File 'lib/printer.rb', line 57 def color? true end |
#error(message) ⇒ Object
Print an error message
39 40 41 |
# File 'lib/printer.rb', line 39 def error() msg("#{color('ERROR:', :red, :bold)} #{}") end |
#fatal(message) ⇒ Object
Print a message describing a fatal error.
44 45 46 |
# File 'lib/printer.rb', line 44 def fatal() msg("#{color('FATAL:', :red, :bold)} #{}") end |
#highline ⇒ Object
17 18 19 20 21 22 |
# File 'lib/printer.rb', line 17 def highline @highline ||= begin require 'highline' HighLine.new end end |
#msg(message) ⇒ Object Also known as: info
Prints a message to stdout. Aliased as info
for compatibility with the logger API.
26 27 28 29 |
# File 'lib/printer.rb', line 26 def msg() stdout.puts stdout.flush end |
#warn(message) ⇒ Object
Print a warning message
34 35 36 |
# File 'lib/printer.rb', line 34 def warn() msg("#{color('WARNING:', :yellow, :bold)} #{}") end |