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, &block) ⇒ 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
84 85 86 87 88 |
# File 'lib/tty/command/result.rb', line 84 def ==(other) return false unless other.is_a?(TTY::Command::Result) @status == other.to_i && to_ary == other.to_ary end |
#each(separator = nil, &block) ⇒ Object
Enumerate over output lines
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/tty/command/result.rb', line 37 def each(separator = nil, &block) sep = separator || TTY::Command.record_separator return unless @out elements = @out.split(sep) if block_given? elements.each(&block) else elements.to_enum end end |
#exit_status ⇒ Object Also known as: exitstatus, status
Information on how the process exited
52 53 54 |
# File 'lib/tty/command/result.rb', line 52 def exit_status @status end |
#exited? ⇒ Boolean Also known as: complete?
70 71 72 |
# File 'lib/tty/command/result.rb', line 70 def exited? @status != nil end |
#failure? ⇒ Boolean Also known as: failed?
79 80 81 |
# File 'lib/tty/command/result.rb', line 79 def failure? !success? end |
#success? ⇒ Boolean
75 76 77 |
# File 'lib/tty/command/result.rb', line 75 def success? exited? ? @status.zero? : false end |
#to_ary ⇒ Object
66 67 68 |
# File 'lib/tty/command/result.rb', line 66 def to_ary [@out, @err] end |
#to_i ⇒ Object
58 59 60 |
# File 'lib/tty/command/result.rb', line 58 def to_i @status end |
#to_s ⇒ Object
62 63 64 |
# File 'lib/tty/command/result.rb', line 62 def to_s @status.to_s end |