Class: TextChecker

Inherits:
Mumukit::Metatest::Checker
  • Object
show all
Defined in:
lib/checker.rb

Defined Under Namespace

Modules: IgnoreCase, IgnoreWhitespace Classes: Comparator, ContainComparator, EqualityComparator, RegexpComparator, ValidIpComparator

Constant Summary collapse

COMPARATORS =
{
  match: TextChecker::RegexpComparator,
  equal: TextChecker::EqualityComparator,
  contain: TextChecker::ContainComparator,
  valid_ip: TextChecker::ValidIpComparator
}

Instance Method Summary collapse

Instance Method Details

#check_assertion(key, input, config, example) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/checker.rb', line 18

def check_assertion(key, input, config, example)
  if key == :keys
    check_keys input, config, example
  else
    check_comparators key, input, config
  end
end

#check_comparators(key, input, config) ⇒ Object



26
27
28
29
30
31
# File 'lib/checker.rb', line 26

def check_comparators(key, input, config)
  COMPARATORS[key]
      .new(config.is_a?(Hash) ? config : {expected: config})
      .compare(input[:source])
      .try { |error| fail error }
end

#check_keys(input, config, example) ⇒ Object



33
34
35
36
37
38
# File 'lib/checker.rb', line 33

def check_keys(input, config, example)
  source_hash = YAML.load(input[:source]).with_indifferent_access
    config.each do |subkey, subconfig|
      check_assertions({source: source_hash[subkey]}, subconfig, example)
  end
end