Sha256: 3fb93328cd13b3a8e8f766b98dc899b3ed5964278e17f9b3c84e943f1a50dacf

Contents?: true

Size: 1.51 KB

Versions: 18

Compression:

Stored size: 1.51 KB

Contents

module W3CValidators
  class Results
    attr_reader :uri, :checked_by, :doctype, :css_level, :charset, :validity, :debug_messages

    def initialize(options = {})
      @messages       = []
      @uri            = options[:uri]
      @checked_by     = options[:checked_by]
      @doctype        = options[:doctype]
      @css_level      = options[:css_level]
      @charset        = options[:charset]
      if options[:validity].kind_of?(String)
        @validity     = options[:validity].downcase.strip == 'true'
      else
        @validity     = options[:validity]
      end
      @debug_messages = {}
    end

    def add_message(type, params = {})
      uri = params[:uri] ||= @uri
      @messages << Message.new(uri, type, params)
    end    

    def add_error(params = {})
      add_message(:error, params)
    end

    def add_warning(params = {})
      add_message(:warning, params)
    end

    def add_debug_message(key, val)
      @debug_messages[key] = val
    end

    # Returns either the +DOCTYPE+ or CSS level, whichever is present.
    def checked_against
      return @doctype if @doctype
      return @css_level if @css_level
      nil
    end

    def is_valid?
      @validity
    end

    # Returns an array of Message objects.
    def errors
      errors = []
      @messages.each { |msg| errors << msg if msg.is_error? }
      errors
    end

    # Returns an array of Message objects.
    def warnings
      errors = []
      @messages.each { |msg| errors << msg if msg.is_warning? }
      errors
    end
  end
end

Version data entries

18 entries across 18 versions & 3 rubygems

Version Path
w3c_validators-1.3.7 lib/w3c_validators/results.rb
w3c_validators-1.3.6 lib/w3c_validators/results.rb
w3c_validators-1.3.5 lib/w3c_validators/results.rb
w3c_validators-1.3.4 lib/w3c_validators/results.rb
w3c_validators-1.3.3 lib/w3c_validators/results.rb
w3c_validators-1.3.2 lib/w3c_validators/results.rb
w3c_validators-1.3.1 lib/w3c_validators/results.rb
w3c_validators-1.3 lib/w3c_validators/results.rb
alexdunae-w3c_validators-1.0.0 lib/w3c_validators/results.rb
frameworks-capybara-0.2.0.rc6 vendor/bundle/ruby/1.8/gems/w3c_validators-1.2/lib/w3c_validators/results.rb
frameworks-capybara-0.2.0.rc5 vendor/bundle/ruby/1.8/gems/w3c_validators-1.2/lib/w3c_validators/results.rb
frameworks-capybara-0.2.0.rc4 vendor/bundle/ruby/1.8/gems/w3c_validators-1.2/lib/w3c_validators/results.rb
frameworks-capybara-0.2.0.rc3 vendor/bundle/ruby/1.8/gems/w3c_validators-1.2/lib/w3c_validators/results.rb
frameworks-capybara-0.2.0.rc2 vendor/bundle/ruby/1.8/gems/w3c_validators-1.2/lib/w3c_validators/results.rb
w3c_validators-1.2 lib/w3c_validators/results.rb
w3c_validators-1.1.1 lib/w3c_validators/results.rb
w3c_validators-1.1 lib/w3c_validators/results.rb
w3c_validators-1.0.2 lib/w3c_validators/results.rb