Class: Rushed::Process

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Process

Returns a new instance of Process.



3
4
5
6
7
8
9
10
# File 'lib/rushed/process.rb', line 3

def initialize(options={})
  @command = options[:command]
  @args = options[:args]
  @stdin = options[:stdin]
  if @command.kind_of?(String) && @command.start_with?('[')
    @command = 'to_stdout' + @command
  end
end

Instance Method Details

#runObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rushed/process.rb', line 12

def run
  paths = @args
  if @stdin.blank? && paths.present?
    @stdin = paths.map { |path| ::File.open(path).read }.join("\n")
  end
  lines = @stdin.present? ? @stdin.split("\n") : []
  array = Rushed::Array.new(lines)
  output = array.instance_eval(@command) || @stdin
  if output.respond_to?(:to_dotsch_output)
    output = output.to_dotsch_output
  end
  if output.kind_of?(::Array)
    output = output.join("\n")
  end
  output.to_s
end