Class: TRMNLP::Reporter

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

Overview

Single sink for user-facing command output. Records every message so specs can assert on what a command would have said, and writes to the underlying stream unless quiet:.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(quiet: false, stream: $stdout) ⇒ Reporter

Returns a new instance of Reporter.



10
11
12
13
14
15
16
17
# File 'lib/trmnlp/reporter.rb', line 10

def initialize(quiet: false, stream: $stdout)
  @quiet = quiet
  @stream = stream
  @messages = []
  # Colour only when the stream is a real terminal, so ANSI codes
  # never leak into piped or redirected output.
  @tty = stream.tty?
end

Instance Attribute Details

#messagesObject (readonly)

Returns the value of attribute messages.



8
9
10
# File 'lib/trmnlp/reporter.rb', line 8

def messages
  @messages
end

Instance Method Details

#green(text) ⇒ Object



24
# File 'lib/trmnlp/reporter.rb', line 24

def green(text) = colorize(text, 32)

#info(message) ⇒ Object



19
20
21
22
# File 'lib/trmnlp/reporter.rb', line 19

def info(message)
  @messages << message
  @stream.puts(message) unless @quiet
end

#red(text) ⇒ Object



26
# File 'lib/trmnlp/reporter.rb', line 26

def red(text) = colorize(text, 31)

#yellow(text) ⇒ Object



25
# File 'lib/trmnlp/reporter.rb', line 25

def yellow(text) = colorize(text, 33)