Class: Dest::Evaluator

Inherits:
Object
  • Object
show all
Defined in:
lib/dest/evaluator.rb

Instance Method Summary collapse

Constructor Details

#initialize(parsed_attributes) ⇒ Evaluator

Returns a new instance of Evaluator.



10
11
12
# File 'lib/dest/evaluator.rb', line 10

def initialize(parsed_attributes)
  @parsed_attributes = parsed_attributes
end

Instance Method Details

#evaluateObject

Evaluates a doctest to see if the expression matches the result. Only true is returned if it matches as the formatter is only going to print out a dot. False provides the needed details for the formatter.



19
20
21
22
23
24
25
26
27
28
# File 'lib/dest/evaluator.rb', line 19

def evaluate
  expr_result = eval(@parsed_attributes[1])

  if expr_result == eval(@parsed_attributes[2])
    [true]
  else
    [false, @parsed_attributes[0], @parsed_attributes[1], @parsed_attributes[2], expr_result]
    # false,    line number,        expression,           expected_result,      actual_result
  end
end