Sha256: a136d27b0e93294e314446b2f7f79906563f4434bd17c33bd50edfffe62cdb9d

Contents?: true

Size: 604 Bytes

Versions: 1

Compression:

Stored size: 604 Bytes

Contents

require 'public_suffix_service'
require 'delegate'

module PageRankr
  class Site < DelegateClass(PublicSuffixService::Domain)
    def initialize(site)
      super(PublicSuffixService.parse(clean(site)))
      valid? or raise DomainInvalid, "The domain provided is invalid."
    end
    
    private
    
    def clean(site)
      site = site.split("://").last # remove protocol
      site = site.split("/").first  # remove path
      site.split("?").first         # remove params
    end
  end

  class << self
    def Site(site)
      site.respond_to?(:domain) ? site : Site.new(site)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
PageRankr-3.0.0 lib/page_rankr/site.rb