Class: EzCapture
- Inherits:
-
Object
- Object
- EzCapture
- Defined in:
- lib/ezcapture.rb
Constant Summary collapse
- VERSION =
version
'1.0'
Instance Attribute Summary collapse
-
#cmd ⇒ Array
readonly
The command sent to Open3.capture.
-
#error ⇒ Errno::ENOENT
readonly
Error object if command failed.
-
#results ⇒ Array
readonly
Array returned by Open3.capture.
Instance Method Summary collapse
-
#initialize(*p_cmd) ⇒ EzCapture
constructor
A new instance of EzCapture.
-
#status ⇒ Process::Status
Status of running the command.
-
#stderr ⇒ String
STDERR from the command.
-
#stdout ⇒ String
STDOUT from the command.
-
#success? ⇒ Boolean
Success or failure of the command.
Constructor Details
#initialize(*p_cmd) ⇒ EzCapture
Returns a new instance of EzCapture.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ezcapture.rb', line 21 def initialize(*p_cmd) super() @results = nil @error = nil # flatten command @cmd = p_cmd.flatten.clone # attempt to run command begin @results = Open3.capture3(*cmd) # catch errors rescue => e @error = e end end |
Instance Attribute Details
#cmd ⇒ Array (readonly)
The command sent to Open3.capture
10 11 12 |
# File 'lib/ezcapture.rb', line 10 def cmd @cmd end |
#error ⇒ Errno::ENOENT (readonly)
Error object if command failed
18 19 20 |
# File 'lib/ezcapture.rb', line 18 def error @error end |
#results ⇒ Array (readonly)
Array returned by Open3.capture
14 15 16 |
# File 'lib/ezcapture.rb', line 14 def results @results end |
Instance Method Details
#status ⇒ Process::Status
Returns status of running the command.
58 59 60 61 62 63 64 |
# File 'lib/ezcapture.rb', line 58 def status if @results return @results[2] else return nil end end |
#stderr ⇒ String
Returns STDERR from the command.
49 50 51 52 53 54 55 |
# File 'lib/ezcapture.rb', line 49 def stderr if @results return @results[1] else return nil end end |
#stdout ⇒ String
Returns STDOUT from the command.
40 41 42 43 44 45 46 |
# File 'lib/ezcapture.rb', line 40 def stdout if @results return @results[0] else return nil end end |
#success? ⇒ Boolean
Returns success or failure of the command.
67 68 69 70 71 72 73 |
# File 'lib/ezcapture.rb', line 67 def success? if status return @results[2].success? else return false end end |