class Mumukit::Templates::ExpectationsHook::SourceExpectation

Public Class Methods

new(expectation, evaluator) click to toggle source
# File lib/mumukit/templates/expectations_hook.rb, line 49
def initialize(expectation, evaluator)
  @expectation = expectation
  @evaluator = evaluator
end
parse(expectation) click to toggle source
# File lib/mumukit/templates/expectations_hook.rb, line 62
def self.parse(expectation)
  parsed = Mulang::Expectation.parse(expectation)
  evaluator = parse_evaluator(parsed.inspection)
  new parsed, evaluator
end

Private Class Methods

parse_evaluator(inspection) click to toggle source
# File lib/mumukit/templates/expectations_hook.rb, line 74
def self.parse_evaluator(inspection)
  SOURCE_EXPECTATION_EVALUATORS[inspection.type]
end

Public Instance Methods

evaluate(content) click to toggle source
# File lib/mumukit/templates/expectations_hook.rb, line 54
def evaluate(content)
  { result: evaluate_inspection(content), expectation: @expectation.to_h }
end
inspection() click to toggle source
# File lib/mumukit/templates/expectations_hook.rb, line 58
def inspection
  @expectation.inspection
end

Private Instance Methods

evaluate_inspection(content) click to toggle source
# File lib/mumukit/templates/expectations_hook.rb, line 70
def evaluate_inspection(content)
  inspection.negated? ^ @evaluator.call(content, inspection.target.value)
end