Class: DataPackage::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/datapackage/validator.rb

Overview

Base class for validators

Direct Known Subclasses

DataPackageValidator

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema_name, opts = {}) ⇒ Validator

Returns a new instance of Validator.



18
19
20
21
# File 'lib/datapackage/validator.rb', line 18

def initialize(schema_name, opts={})
    @schema_name = schema_name
    @opts = opts
end

Instance Attribute Details

#messagesObject (readonly)

Returns the value of attribute messages.



6
7
8
# File 'lib/datapackage/validator.rb', line 6

def messages
  @messages
end

Class Method Details

.create(profile, opts = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/datapackage/validator.rb', line 8

def Validator.create(profile, opts={})
    if profile == :simpledataformat
        return SimpleDataFormatValidator.new(profile, opts)
    end
    if profile == :datapackage
        return DataPackageValidator.new(profile, opts)
    end
    return Validator.new(profile, opts)
end

Instance Method Details

#valid?(package, strict = false) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
# File 'lib/datapackage/validator.rb', line 23

def valid?(package, strict=false)
    validate( package )
    return @messages[:errors].empty? if !strict
    return @messages[:errors].empty? && @messages[:warnings].empty? 
end

#validate(package) ⇒ Object



29
30
31
32
33
34
# File 'lib/datapackage/validator.rb', line 29

def validate( package )
    @messages = {:errors=>[], :warnings=>[]}
    validate_with_schema( package )
    validate_integrity( package )
    return @messages
end