Class: PopCap::Commander

Inherits:
Object
  • Object
show all
Defined in:
lib/pop_cap/ffmpeg/commander.rb

Overview

Public: This is a wrapper for the Open3 Ruby Standard Library.

Examples

options = %W{ls} + %W{-lh}
Commander.new(options).execute.output
# => <directory contents>

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Commander

Public: Initialize

args - Arguments should be escaped with an interpolated literal.

Raises:

  • (ArgumentError)


18
19
20
21
22
23
# File 'lib/pop_cap/ffmpeg/commander.rb', line 18

def initialize(*args)
  raise(ArgumentError, error_message) if args.empty?
  @args = args
  @command = shell_escaped_arguments
  @executed = []
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



13
14
15
# File 'lib/pop_cap/ffmpeg/commander.rb', line 13

def command
  @command
end

Instance Method Details

#executeObject

Public: Execute the command using Open3.capture3. It will return an instance of Commander, in order to chain methods.



29
30
31
32
# File 'lib/pop_cap/ffmpeg/commander.rb', line 29

def execute
  @executed = Open3.capture3(*command)
  self
end

#stderrObject

Public: Open3.capture3 returns an array of three elements. The second element returned is stderr.



44
45
46
# File 'lib/pop_cap/ffmpeg/commander.rb', line 44

def stderr
  @executed[1]
end

#stdoutObject

Public: Open3.capture3 returns an array of three elements. The first element returned is stdout.



37
38
39
# File 'lib/pop_cap/ffmpeg/commander.rb', line 37

def stdout
  @executed[0]
end

#success?Boolean

Public: Open3.capture3 returns an array of three elements. The third element returned is status. Status can have a ‘success?’ of true or false.

Examples

self.success?
# => true

Returns:

  • (Boolean)


57
58
59
# File 'lib/pop_cap/ffmpeg/commander.rb', line 57

def success?
  @executed[2].success?
end