Class: Printer

Inherits:
Object
  • Object
show all
Defined in:
lib/printer.rb

Overview

Greg Seitz

Copyright 2013, eBay Inc.
All rights reserved.
http://www.ebay.com

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#stderrObject (readonly)

Returns the value of attribute stderr.



10
11
12
# File 'lib/printer.rb', line 10

def stderr
  @stderr
end

#stdinObject (readonly)

Returns the value of attribute stdin.



11
12
13
# File 'lib/printer.rb', line 11

def stdin
  @stdin
end

#stdoutObject (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

Returns:

  • (Boolean)


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(message)
  msg("#{color('ERROR:', :red, :bold)} #{message}")
end

#fatal(message) ⇒ Object

Print a message describing a fatal error.



44
45
46
# File 'lib/printer.rb', line 44

def fatal(message)
  msg("#{color('FATAL:', :red, :bold)} #{message}")
end

#highlineObject



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(message)
  stdout.puts message
  stdout.flush
end

#warn(message) ⇒ Object

Print a warning message



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

def warn(message)
  msg("#{color('WARNING:', :yellow, :bold)} #{message}")
end