Module: SciolyFF::Validator::Sections
- Defined in:
- lib/sciolyff/validator/sections.rb
Overview
Generic tests for (sub-)sections and types. Including classes must have two hashes REQUIRED and OPTIONAL (see other files in this dir for examples)
Instance Method Summary collapse
- #all_required_sections?(rep, logger) ⇒ Boolean
- #no_extra_sections?(rep, logger) ⇒ Boolean
- #sections_are_correct_type?(rep, logger) ⇒ Boolean
Instance Method Details
#all_required_sections?(rep, logger) ⇒ Boolean
7 8 9 10 11 12 |
# File 'lib/sciolyff/validator/sections.rb', line 7 def all_required_sections?(rep, logger) missing = self.class::REQUIRED.keys - rep.keys return true if missing.empty? logger.error "missing required sections: #{missing.join ', '}" end |
#no_extra_sections?(rep, logger) ⇒ Boolean
14 15 16 17 18 19 |
# File 'lib/sciolyff/validator/sections.rb', line 14 def no_extra_sections?(rep, logger) extra = rep.keys - (self.class::REQUIRED.keys + self.class::OPTIONAL.keys) return true if extra.empty? logger.error "extra section(s) found: #{extra.join ', '}" end |
#sections_are_correct_type?(rep, logger) ⇒ Boolean
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/sciolyff/validator/sections.rb', line 21 def sections_are_correct_type?(rep, logger) correct_types = self.class::REQUIRED.merge self.class::OPTIONAL rep.all? do |key, value| correct = correct_types[key] next true if (correct.instance_of?(Array) && correct.include?(value)) || (value.instance_of? correct) logger.error "#{key}: #{value} is not #{correct}" end end |