Class: Cid::Validation

Inherits:
Object
  • Object
show all
Defined in:
lib/cid/validation.rb

Class Method Summary collapse

Class Method Details

.validate(path, ignore = []) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cid/validation.rb', line 7

def self.validate(path, ignore = [])
  result = {}

  paths = Dir.glob("#{path}/**")

  paths.each do |path|
    next if ignore.include?(path.split("/").last)

    begin
      schema = Csvlint::Schema.load_from_json_table(File.new(Dir["#{path}/schema.json"][0]))
    rescue
      schema = nil
    end

    Dir["#{path}/*.csv"].each do |csv|
      validator = Csvlint::Validator.new(File.new(csv), nil, schema)
      ref = csv.split("/").last(2).join("/")
      result[ref] = {}

      result[ref][:errors] = validator.errors
      result[ref][:warnings] = validator.warnings
    end
  end

  result
end