Class: Anywhere::Result

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmd) ⇒ Result

Returns a new instance of Result.



5
6
7
8
9
# File 'lib/anywhere/result.rb', line 5

def initialize(cmd)
  @cmd = cmd
  @stdout = []
  @stderr = []
end

Instance Attribute Details

#cmdObject

Returns the value of attribute cmd.



3
4
5
# File 'lib/anywhere/result.rb', line 3

def cmd
  @cmd
end

#exit_statusObject

Returns the value of attribute exit_status.



3
4
5
# File 'lib/anywhere/result.rb', line 3

def exit_status
  @exit_status
end

#stderrObject

Returns the value of attribute stderr.



3
4
5
# File 'lib/anywhere/result.rb', line 3

def stderr
  @stderr
end

#stdoutObject

Returns the value of attribute stdout.



3
4
5
# File 'lib/anywhere/result.rb', line 3

def stdout
  @stdout
end

Instance Method Details

#add_stderr(line) ⇒ Object



11
12
13
# File 'lib/anywhere/result.rb', line 11

def add_stderr(line)
  @stderr << line
end

#add_stdout(line) ⇒ Object



15
16
17
# File 'lib/anywhere/result.rb', line 15

def add_stdout(line)
  @stdout << line
end

#finished!(time = Time.now) ⇒ Object



31
32
33
# File 'lib/anywhere/result.rb', line 31

def finished!(time = Time.now)
  @finished = time
end

#inspectObject



43
44
45
46
47
48
49
50
# File 'lib/anywhere/result.rb', line 43

def inspect
  parts = ["run_time=#{run_time}"]
  parts << "cmd=<#{@cmd}>"
  parts << "stdout=#{inspect_string(@stdout)}"
  parts << "stderr=#{inspect_string(@stderr)}"
  parts << "exit_status=#{@exit_status}"
  "<" + parts.join(", ") + ">"
end

#inspect_string(string) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/anywhere/result.rb', line 52

def inspect_string(string)
  if string.empty?
    "<empty>" 
  else
    "<#{string.count} lines, #{string.join(" ").length} chars>"
  end
end

#run_timeObject



39
40
41
# File 'lib/anywhere/result.rb', line 39

def run_time
  @finished - @started
end

#started!(time = Time.now) ⇒ Object



27
28
29
# File 'lib/anywhere/result.rb', line 27

def started!(time = Time.now)
  @started = time
end

#success?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/anywhere/result.rb', line 35

def success?
  @exit_status == 0
end