Class: Ukiryu::Pipe

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

Overview

Pipe redirection for inter-process communication

Pipes allow the output of one command to become the input of another. This is represented by special file path markers.

Examples:

# Pipe output of command1 to command2
result1 = command1.execute(output: Pipe.to("command2"))

Using special syntax in tools

# Ghostscript: -sOutputFile=%pipe%lpr
# Tar: --to-command=COMMAND

Constant Summary collapse

MARKER =

Special marker for pipe output

'%pipe%'

Class Method Summary collapse

Class Method Details

.parse(value) ⇒ String?

Parse a pipe marker

Examples:

Pipe.parse("%pipe%lpr") # => "lpr"

Parameters:

  • value (String)

    the pipe marker string

Returns:

  • (String, nil)

    the command if it’s a pipe marker



89
90
91
92
93
94
# File 'lib/ukiryu/io.rb', line 89

def self.parse(value)
  return nil unless value.is_a?(String)
  return nil unless value.start_with?(MARKER)

  value.sub(MARKER, '')
end

.pipe?(value) ⇒ Boolean

Check if a value is a pipe marker

Parameters:

  • value (String)

    the value to check

Returns:

  • (Boolean)

    true if it’s a pipe marker



100
101
102
103
104
# File 'lib/ukiryu/io.rb', line 100

def self.pipe?(value)
  return false unless value.is_a?(String)

  value.start_with?(MARKER)
end

.to(command) ⇒ String

Create a pipe to a command

Examples:

Pipe.to("lpr") # => "%pipe%lpr"

Parameters:

  • command (String)

    the command to pipe to

Returns:

  • (String)

    the pipe marker for use in CLI options



78
79
80
# File 'lib/ukiryu/io.rb', line 78

def self.to(command)
  "#{MARKER}#{command}"
end