Class: ReturnCodeEvaluator

Inherits:
Object
  • Object
show all
Defined in:
lib/record/return_code_evaluator.rb

Constant Summary collapse

SUCCESS_RETURN_CODE =
0
FAILURE_RETURN_CODE =
1

Instance Method Summary collapse

Constructor Details

#initialize(success_detection) ⇒ ReturnCodeEvaluator

Returns a new instance of ReturnCodeEvaluator.



6
7
8
# File 'lib/record/return_code_evaluator.rb', line 6

def initialize success_detection
 @success_detection = success_detection
end

Instance Method Details

#return_code(process) ⇒ Object



10
11
12
13
# File 'lib/record/return_code_evaluator.rb', line 10

def return_code process
  return process.return_code unless @success_detection
  return_code_from_output process.output
end

#return_code_from_output(output) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/record/return_code_evaluator.rb', line 15

def return_code_from_output output
	space_or_start_of_line = "( |^)"
   if output =~ /#{space_or_start_of_line}#{@success_detection}/ then
	  SUCCESS_RETURN_CODE
	else
		FAILURE_RETURN_CODE
	end
end