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

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')).

See Validator#new for proxy server options.



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

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.



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

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.



32
33
34
# File 'lib/w3c_validators/feed_validator.rb', line 32

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

#validate_uri(url) ⇒ Object

Validate a feed URI using a SOAP request.

Returns W3CValidators::Results.



25
26
27
# File 'lib/w3c_validators/feed_validator.rb', line 25

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