Class: TTY::Command::Result
- Inherits:
-
Object
- Object
- TTY::Command::Result
- Includes:
- Enumerable
- Defined in:
- lib/tty/command/result.rb
Overview
Encapsulates the information on the command executed
Instance Attribute Summary collapse
-
#err ⇒ Object
(also: #stderr)
readonly
All data written out to process’s stdin stream.
-
#out ⇒ Object
(also: #stdout)
readonly
All data written out to process’s stdout stream.
-
#runtime ⇒ Object
readonly
Total command execution time.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#each(separator = nil) ⇒ Object
Enumerate over output lines.
-
#exit_status ⇒ Object
(also: #exitstatus, #status)
Information on how the process exited.
- #exited? ⇒ Boolean (also: #complete?)
- #failure? ⇒ Boolean (also: #failed?)
-
#initialize(status, out, err, runtime = 0.0) ⇒ Result
constructor
Create a result.
- #success? ⇒ Boolean
- #to_ary ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(status, out, err, runtime = 0.0) ⇒ Result
Create a result
25 26 27 28 29 30 |
# File 'lib/tty/command/result.rb', line 25 def initialize(status, out, err, runtime = 0.0) @status = status @out = out @err = err @runtime = runtime end |
Instance Attribute Details
#err ⇒ Object (readonly) Also known as: stderr
All data written out to process’s stdin stream
16 17 18 |
# File 'lib/tty/command/result.rb', line 16 def err @err end |
#out ⇒ Object (readonly) Also known as: stdout
All data written out to process’s stdout stream
12 13 14 |
# File 'lib/tty/command/result.rb', line 12 def out @out end |
#runtime ⇒ Object (readonly)
Total command execution time
20 21 22 |
# File 'lib/tty/command/result.rb', line 20 def runtime @runtime end |
Instance Method Details
#==(other) ⇒ Object
83 84 85 86 |
# File 'lib/tty/command/result.rb', line 83 def ==(other) return false unless other.is_a?(TTY::Command::Result) @status == other.to_i && to_ary == other.to_ary end |
#each(separator = nil) ⇒ Object
Enumerate over output lines
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tty/command/result.rb', line 37 def each(separator = nil) sep = separator || TTY::Command.record_separator return unless @out elements = @out.split(sep) if block_given? elements.each { |line| yield(line) } else elements.to_enum end end |
#exit_status ⇒ Object Also known as: exitstatus, status
Information on how the process exited
51 52 53 |
# File 'lib/tty/command/result.rb', line 51 def exit_status @status end |
#exited? ⇒ Boolean Also known as: complete?
69 70 71 |
# File 'lib/tty/command/result.rb', line 69 def exited? @status != nil end |
#failure? ⇒ Boolean Also known as: failed?
78 79 80 |
# File 'lib/tty/command/result.rb', line 78 def failure? !success? end |
#success? ⇒ Boolean
74 75 76 |
# File 'lib/tty/command/result.rb', line 74 def success? exited? ? @status.zero? : false end |
#to_ary ⇒ Object
65 66 67 |
# File 'lib/tty/command/result.rb', line 65 def to_ary [@out, @err] end |
#to_i ⇒ Object
57 58 59 |
# File 'lib/tty/command/result.rb', line 57 def to_i @status end |
#to_s ⇒ Object
61 62 63 |
# File 'lib/tty/command/result.rb', line 61 def to_s @status.to_s end |