class Optic14n::CanonicalizedUrls

Canonicalizes a set of URLs

Attributes

each[R]
failures[R]
output_set[R]
seen[R]

Public Class Methods

from_urls(urls, options = {}) click to toggle source

Canonicalize given urls. options will be passed to BLURI.parse

# File lib/optic14n/canonicalized_urls.rb, line 43
def self.from_urls(urls, options = {})
  CanonicalizedUrls.new(urls, options).tap(&:canonicalize!)
end
new(urls, options) click to toggle source
# File lib/optic14n/canonicalized_urls.rb, line 13
def initialize(urls, options)
  @urls = urls
  @options = options
end

Public Instance Methods

canonicalize!() click to toggle source
# File lib/optic14n/canonicalized_urls.rb, line 18
def canonicalize!
  @seen = 0
  @failures = {}
  @output_set = Set.new

  @urls.each do |url|
    begin
      @output_set.add(BLURI(url).canonicalize!(@options))
    rescue StandardError => e
      failures[url] = e
    end
    @seen += 1
  end
end
write(filename) click to toggle source
# File lib/optic14n/canonicalized_urls.rb, line 33
def write(filename)
  File.open(filename, "w") do |file|
    @output_set.each do |url|
      file.puts url
    end
  end
end