Sha256: 19b8296265fbd55a56644636b78a5e1c93e2887dc62c1568ea6e36d087b39ee2

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: 'https://html5.validator.nu/' }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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