Class: DataPackage::Validator
- Inherits:
-
Object
- Object
- DataPackage::Validator
- Defined in:
- lib/datapackage/validator.rb
Overview
Base class for validators
Direct Known Subclasses
Instance Attribute Summary collapse
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(schema_name, opts = {}) ⇒ Validator
constructor
A new instance of Validator.
- #valid?(package, strict = false) ⇒ Boolean
- #validate(package) ⇒ Object
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
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
6 7 8 |
# File 'lib/datapackage/validator.rb', line 6 def @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
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 |