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
# File 'lib/trmnlp/reporter.rb', line 10

def initialize(quiet: false, stream: $stdout)
  @quiet = quiet
  @stream = stream
  @messages = []
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



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

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

#info(message) ⇒ Object



16
17
18
19
# File 'lib/trmnlp/reporter.rb', line 16

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

#yellow(text) ⇒ Object



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

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