class CDONFeedValidator::Validator

Constants

XSDDIR

Attributes

errors[R]
options[R]
xml[R]

Public Class Methods

new(xml, **options) click to toggle source
# File lib/cdon_feed_validator/validator.rb, line 9
def initialize(xml, **options)
  @xml = Nokogiri::XML xml
  @options = options.as_json
  @errors = []
end

Public Instance Methods

valid?() click to toggle source
# File lib/cdon_feed_validator/validator.rb, line 15
def valid?
  validate
  errors.empty?
end
validate() click to toggle source
# File lib/cdon_feed_validator/validator.rb, line 20
def validate
  @errors = file
    .validate(xml)
    .map(&:to_s) || []
end

Private Instance Methods

file() click to toggle source
# File lib/cdon_feed_validator/validator.rb, line 32
def file
  string = File.read File.expand_path filename, XSDDIR

  # Replace schema location references with ones pointing to local xsd
  # files
  string.gsub! \
    'schemaLocation="',
    "schemaLocation=\"#{XSDDIR}/"

  Nokogiri::XML::Schema string
end
filename() click to toggle source
# File lib/cdon_feed_validator/validator.rb, line 28
def filename
  raise NotImplementedError, 'must be implemented by descendents'
end