Class: CDONFeedValidator::Validator

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

Direct Known Subclasses

Product

Constant Summary collapse

XSDDIR =
File.expand_path('../xsd', __dir__)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml, **options) ⇒ Validator

Returns a new instance of Validator.



9
10
11
12
13
# File 'lib/cdon_feed_validator/validator.rb', line 9

def initialize(xml, **options)
  @xml = Nokogiri::XML xml
  @options = options.as_json
  @errors = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



7
8
9
# File 'lib/cdon_feed_validator/validator.rb', line 7

def errors
  @errors
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/cdon_feed_validator/validator.rb', line 7

def options
  @options
end

#xmlObject (readonly)

Returns the value of attribute xml.



7
8
9
# File 'lib/cdon_feed_validator/validator.rb', line 7

def xml
  @xml
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


15
16
17
18
# File 'lib/cdon_feed_validator/validator.rb', line 15

def valid?
  validate
  errors.empty?
end

#validateObject



20
21
22
23
24
# File 'lib/cdon_feed_validator/validator.rb', line 20

def validate
  @errors = file
    .validate(xml)
    .map(&:to_s) || []
end