Class: W3CValidators::FeedValidator

Inherits:
Validator
  • Object
show all
Defined in:
lib/w3c_validators/feed_validator.rb

Constant Summary collapse

FEED_VALIDATOR_URI =
'http://validator.w3.org/feed/check.cgi'

Constants inherited from Validator

Validator::HEAD_ERROR_COUNT_HEADER, Validator::HEAD_STATUS_HEADER, Validator::SOAP_OUTPUT_PARAM, Validator::USER_AGENT, Validator::VERSION

Instance Attribute Summary

Attributes inherited from Validator

#results, #validator_uri

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ FeedValidator

Create a new instance of the FeedValidator.

Options

You can pass in your own validator’s URI (i.e. FeedValidator.new(:validator_uri => 'http://localhost/check')).



10
11
12
13
14
15
16
17
18
# File 'lib/w3c_validators/feed_validator.rb', line 10

def initialize(options = {})
  if options[:validator_uri]
    @validator_uri = URI.parse(options[:validator_uri])
    options.delete(options[:validator_uri])
  else
    @validator_uri = URI.parse(FEED_VALIDATOR_URI)
  end
  super(options)
end

Instance Method Details

#validate_file(file_path) ⇒ Object

Validate a local feed file.

file_path may be either the fully-expanded path to the file or an IO object (like File).

Returns W3CValidators::Results.



40
41
42
43
44
45
46
47
# File 'lib/w3c_validators/feed_validator.rb', line 40

def validate_file(file_path)
  if file_path.respond_to? :read
    src = file_path.read
  else
    src = read_local_file(file_path)
  end
  return validate_text(src)
end

#validate_text(text) ⇒ Object

Validate a feed from a string.

Returns W3CValidators::Results.



30
31
32
# File 'lib/w3c_validators/feed_validator.rb', line 30

def validate_text(text)
  return validate({:rawdata => text})
end

#validate_uri(url) ⇒ Object

Validate a feed URI using a SOAP request.

Returns W3CValidators::Results.



23
24
25
# File 'lib/w3c_validators/feed_validator.rb', line 23

def validate_uri(url)
  return validate({:url => url})
end