Module: StructureChecker

Defined in:
lib/clingon/helpers/structure_checker.rb

Class Method Summary collapse

Class Method Details

.check(structure) ⇒ Object



2
3
4
5
6
# File 'lib/clingon/helpers/structure_checker.rb', line 2

def self.check(structure)
  raise('Structure must be an array') unless structure.instance_of?(Array)
  StructureChecker.verify_contents(structure)
  structure
end

.verify_contents(structure) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/clingon/helpers/structure_checker.rb', line 8

def self.verify_contents(structure)
  structure.each do |el|
    raise('Each element of structure must contain name key') unless el[:name]
    if el[:type]
      valid = [
        'int',
        'float',
        'num',
        'bool'
      ]
      unless valid.include?(el[:type])
        raise("Valid types are: #{valid.join(', ')}")
      end
    end
  end
end