Class: Mpx::Result

Inherits:
Object
  • Object
show all
Includes:
ANSI::Code
Defined in:
lib/mpx/result.rb

Overview

Represents the output of a command.

Instance Method Summary collapse

Constructor Details

#initialize(name, out, status) ⇒ Result

Returns a new instance of Result.



9
10
11
12
13
# File 'lib/mpx/result.rb', line 9

def initialize(name, out, status)
  @name = name
  @out = out.strip
  @status = status
end

Instance Method Details

#status_stringObject



26
27
28
29
30
31
# File 'lib/mpx/result.rb', line 26

def status_string
  status = @status.exitstatus
  color = status.zero? ? :green : :red
  message = status.zero? ? 'Done!' : "Exited with code #{status}."
  return send(color) { message }
end

#to_sObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/mpx/result.rb', line 15

def to_s
  out = @out.empty? ? yellow { 'No output.' } : @out
  return [
    cyan { @name },
    cyan { '-' * @name.length },
    out,
    '',
    status_string
  ].join("\n")
end