Class: EzCapture

Inherits:
Object
  • Object
show all
Defined in:
lib/ezcapture.rb

Constant Summary collapse

VERSION =

version

'1.0'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*p_cmd) ⇒ EzCapture

Returns a new instance of EzCapture.

Parameters:

  • p_cmd (Array)

    one or more strings to send as a command



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

#cmdArray (readonly)

The command sent to Open3.capture

Returns:

  • (Array)

    individual strings in the command



10
11
12
# File 'lib/ezcapture.rb', line 10

def cmd
  @cmd
end

#errorErrno::ENOENT (readonly)

Error object if command failed

Returns:

  • (Errno::ENOENT)


18
19
20
# File 'lib/ezcapture.rb', line 18

def error
  @error
end

#resultsArray (readonly)

Array returned by Open3.capture

Returns:

  • (Array)


14
15
16
# File 'lib/ezcapture.rb', line 14

def results
  @results
end

Instance Method Details

#statusProcess::Status

Returns status of running the command.

Returns:

  • (Process::Status)

    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

#stderrString

Returns STDERR from the command.

Returns:

  • (String)

    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

#stdoutString

Returns STDOUT from the command.

Returns:

  • (String)

    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.

Returns:

  • (Boolean)

    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