Class: Mumukit::Templates::ExpectationsHook

Inherits:
Hook
  • Object
show all
Defined in:
lib/mumukit/templates/expectations_hook.rb

Direct Known Subclasses

MulangExpectationsHook

Defined Under Namespace

Classes: SourceExpectation

Constant Summary collapse

SOURCE_EXPECTATION_EVALUATORS =
{
  'SourceRepeats' => lambda { |source, target| source.scan(target).count > 1 },
  'SourceContains' => lambda { |source, target| source.include? target },
  'SourceEquals' => lambda { |source, target| source == target },
  'SourceEqualsIgnoreSpaces' => lambda { |source, target| source.delete(' ') == target.delete(' ') }
}
SOURCE_EXPECTATIONS =
SOURCE_EXPECTATION_EVALUATORS.keys.flat_map { |it| [it, "Not:#{it}"] }

Instance Attribute Summary

Attributes inherited from Hook

#config

Instance Method Summary collapse

Methods inherited from Hook

#env, #initialize, #logger, #method_missing, #should_forward_to_config?, stateful_through, #t

Methods included from WithContentType

#content_type

Constructor Details

This class inherits a constructor from Mumukit::Hook

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Mumukit::Hook

Instance Method Details

#compile(request) ⇒ Object



13
14
15
# File 'lib/mumukit/templates/expectations_hook.rb', line 13

def compile(request)
  { request: request, expectations: compile_expectations(request) }
end

#run!(spec) ⇒ Object



17
18
19
# File 'lib/mumukit/templates/expectations_hook.rb', line 17

def run!(spec)
  spec[:expectations][:source].map { |it| it.evaluate spec[:request][:content] }
end