Sha256: 7a1557ec7ad64af1f4334816d4e8d08e5529e2c3dd93300527f71b12d6e6f30d

Contents?: true

Size: 750 Bytes

Versions: 1

Compression:

Stored size: 750 Bytes

Contents

require 'httparty'
require 'json'

module Nunchaku
  class Checker
    attr_reader :url, :checker_uri

    def initialize(url, options = {})
      options = defaults.merge(options)

      @url         = url
      @checker_uri = options[:checker_uri]
    end

    def raw
      @raw ||= JSON.parse HTTParty.get("#{checker_uri}?out=json&doc=#{@url}").body
    end

    def messages
      @messages ||= raw['messages'].map { |message| Nunchaku::Message.new(message) }
    end

    def errors
      messages.select { |message| message.type == 'error' }
    end

    def warnings
      messages.select { |message| message.subtype == 'warning' }
    end

    private

    def defaults
      { checker_uri: 'http://validator.w3.org/nu/' }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nunchaku-0.1.1 lib/nunchaku/checker.rb