Class: Datacite::Validators::AttributesValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/datacite/validators/attributes_validator.rb

Overview

Validate a hash of attributes against the DataCite schema

Instance Method Summary collapse

Constructor Details

#initialize(attributes:) ⇒ AttributesValidator

Returns a new instance of AttributesValidator.

Parameters:

  • attributes (Hash)

    for a DataCite API request



11
12
13
# File 'lib/datacite/validators/attributes_validator.rb', line 11

def initialize(attributes:)
  @attributes = attributes
end

Instance Method Details

#errorsObject



20
21
22
# File 'lib/datacite/validators/attributes_validator.rb', line 20

def errors
  results.map { |result| result.fetch('error') }
end

#valid?Boolean

Returns true if valid, false if not.

Returns:

  • (Boolean)

    true if valid, false if not



16
17
18
# File 'lib/datacite/validators/attributes_validator.rb', line 16

def valid?
  results.none? # If there are no results (an Enumerator), there were no errors, thus valid
end