Class: Rushed::Process
- Inherits:
-
Object
- Object
- Rushed::Process
- Defined in:
- lib/rushed/process.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Process
constructor
A new instance of Process.
- #run ⇒ Object
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(={}) @command = [:command] @args = [:args] @stdin = [:stdin] if @command.kind_of?(String) && @command.start_with?('[') @command = 'to_stdout' + @command end end |
Instance Method Details
#run ⇒ Object
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 |