Permalink
Browse files

Removed dependency on domainatrix and replaced with better maintained…

… public_suffix gem
  • Loading branch information...
1 parent f8b52f7 commit 9efdda449dbe57fe348e603bc908401dbc1c7a6c @dparis dparis committed Oct 7, 2012
Showing with 12 additions and 22 deletions.
  1. +1 −2 Rakefile
  2. +7 −16 lib/postrank-uri.rb
  3. +4 −4 postrank-uri.gemspec
View
@@ -2,5 +2,4 @@ require 'bundler'
Bundler::GemHelper.install_tasks
require 'rspec/core/rake_task'
-
-Rspec::Core::RakeTask.new(:spec)
+RSpec::Core::RakeTask.new(:spec)
View
@@ -1,22 +1,16 @@
# -*- encoding: utf-8 -*-
require 'addressable/uri'
-require 'domainatrix'
require 'digest/md5'
require 'nokogiri'
+require 'public_suffix'
require 'yaml'
module Addressable
class URI
def domain
- begin
- dp = Domainatrix.parse(self)
- rescue
- return nil
- end
-
- dom = dp.public_suffix
- dom = dp.domain.downcase + "." + dom unless dp.domain.empty?
+ host = self.host
+ (host && PublicSuffix.valid?(host)) ? PublicSuffix.parse(host).domain : nil
end
def normalized_query
@@ -103,11 +97,10 @@ def extract(text)
return [] if !text
urls = []
text.to_s.scan(URIREGEX[:valid_url]) do |all, before, url, protocol, domain, path, query|
- begin
+ # Only extract the URL if the domain is valid
+ if PublicSuffix.valid?(domain)
url = clean(url)
- Domainatrix.parse(url)
urls.push url.to_s
- rescue NoMethodError
end
end
@@ -223,10 +216,8 @@ def parse(uri, opts = {})
end
def valid?(uri)
- Domainatrix.parse(uri)
- true
- rescue
- false
+ cleaned_uri = clean(uri, :raw => true)
+ cleaned_uri && cleaned_uri.host && PublicSuffix.valid?(cleaned_uri.host)
end
end
end
View
@@ -14,11 +14,11 @@ Gem::Specification.new do |s|
s.rubyforge_project = "postrank-uri"
- s.add_dependency "addressable", ">= 2.3.0"
- s.add_dependency "domainatrix"
- s.add_dependency "nokogiri"
+ s.add_dependency "addressable", "~> 2.3.0"
+ s.add_dependency "public_suffix", "~> 1.1.3"
+ s.add_dependency "nokogiri", "~> 1.5.5"
+
s.add_development_dependency "rspec"
- #s.add_development_dependency "idn" # test with idn
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")

0 comments on commit 9efdda4

Please sign in to comment.