f1sherman-domainatrix 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/domainatrix.rb +2 -2
- data/lib/domainatrix/domain_parser.rb +3 -1
- data/spec/domainatrix/domain_parser_spec.rb +28 -2
- data/spec/domainatrix_spec.rb +15 -7
- metadata +3 -3
data/lib/domainatrix.rb
CHANGED
@@ -5,10 +5,10 @@ require 'domainatrix/domain_parser.rb'
|
|
5
5
|
require 'domainatrix/url.rb'
|
6
6
|
|
7
7
|
module Domainatrix
|
8
|
-
VERSION = "0.0.
|
8
|
+
VERSION = "0.0.11"
|
9
9
|
DOMAIN_PARSER = DomainParser.new("#{File.dirname(__FILE__)}/effective_tld_names.dat")
|
10
10
|
|
11
11
|
def self.parse(url)
|
12
12
|
Url.new(DOMAIN_PARSER.parse(url))
|
13
13
|
end
|
14
|
-
end
|
14
|
+
end
|
@@ -31,6 +31,7 @@ module Domainatrix
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def parse(url)
|
34
|
+
url.downcase!
|
34
35
|
uri = URI.parse(url)
|
35
36
|
if uri.query
|
36
37
|
path = "#{uri.path}?#{uri.query}"
|
@@ -46,6 +47,7 @@ module Domainatrix
|
|
46
47
|
end
|
47
48
|
|
48
49
|
def parse_domains_from_host(host)
|
50
|
+
host.downcase!
|
49
51
|
parts = host.split(".").reverse
|
50
52
|
public_suffix = []
|
51
53
|
domain = ""
|
@@ -74,4 +76,4 @@ module Domainatrix
|
|
74
76
|
{:public_suffix => public_suffix.reverse.join("."), :domain => domain, :subdomain => subdomains.reverse.join(".")}
|
75
77
|
end
|
76
78
|
end
|
77
|
-
end
|
79
|
+
end
|
@@ -24,7 +24,7 @@ describe "domain parser" do
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
describe
|
27
|
+
describe :parse do
|
28
28
|
it "returns a hash of parts" do
|
29
29
|
@domain_parser.parse("http://pauldix.net").should be_a Hash
|
30
30
|
end
|
@@ -68,4 +68,30 @@ describe "domain parser" do
|
|
68
68
|
@domain_parser.parse("http://bar.foo.pauldix.co.uk")[:subdomain].should == "bar.foo"
|
69
69
|
end
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
|
+
describe :parse_domains_from_host do
|
73
|
+
it "should parse from a lowercase host" do
|
74
|
+
@domain_parser.parse_domains_from_host("foo.pauldix.net")[:domain].should == "pauldix"
|
75
|
+
@domain_parser.parse_domains_from_host("foo.pauldix.net")[:subdomain].should == "foo"
|
76
|
+
@domain_parser.parse_domains_from_host("foo.pauldix.net")[:public_suffix].should == "net"
|
77
|
+
end
|
78
|
+
it "should parse from a mixed case host" do
|
79
|
+
@domain_parser.parse_domains_from_host("foo.pauldix.NET")[:domain].should == "pauldix"
|
80
|
+
@domain_parser.parse_domains_from_host("foo.pauldix.NET")[:subdomain].should == "foo"
|
81
|
+
@domain_parser.parse_domains_from_host("foo.pauldix.NET")[:public_suffix].should == "net"
|
82
|
+
end
|
83
|
+
it "should parse from an uppercase host" do
|
84
|
+
@domain_parser.parse_domains_from_host("FOO.PAULDIX.NET")[:domain].should == "pauldix"
|
85
|
+
@domain_parser.parse_domains_from_host("FOO.PAULDIX.NET")[:subdomain].should == "foo"
|
86
|
+
@domain_parser.parse_domains_from_host("FOO.PAULDIX.NET")[:public_suffix].should == "net"
|
87
|
+
end
|
88
|
+
it "should parse from an empty host" do
|
89
|
+
@domain_parser.parse_domains_from_host("")[:domain].should == ""
|
90
|
+
@domain_parser.parse_domains_from_host("")[:subdomain].should == ""
|
91
|
+
@domain_parser.parse_domains_from_host("")[:public_suffix].should == ""
|
92
|
+
end
|
93
|
+
it "should raise an error for invalid input" do
|
94
|
+
lambda { @domain_parser.parse_domains_from_host(nil) }.should raise_error
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
data/spec/domainatrix_spec.rb
CHANGED
@@ -5,12 +5,20 @@ describe "domainatrix" do
|
|
5
5
|
Domainatrix.parse("http://pauldix.net").should be_a Domainatrix::Url
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
8
|
+
describe :parse do
|
9
|
+
it "should canonicalize" do
|
10
|
+
Domainatrix.parse("http://pauldix.net").canonical.should == "net.pauldix"
|
11
|
+
Domainatrix.parse("http://pauldix.NET").canonical.should == "net.pauldix"
|
12
|
+
Domainatrix.parse("http://PAULDIX.net").canonical.should == "net.pauldix"
|
13
|
+
Domainatrix.parse("http://PAULDIX.NET").canonical.should == "net.pauldix"
|
14
|
+
Domainatrix.parse("HTTP://PAULDIX.NET").canonical.should == "net.pauldix"
|
15
|
+
lambda { Domainatrix.parse("") }.should raise_error
|
16
|
+
lambda { Domainatrix.parse(nil) }.should raise_error
|
17
|
+
Domainatrix.parse("http://pauldix.net/foo.html").canonical.should == "net.pauldix/foo.html"
|
18
|
+
Domainatrix.parse("http://pauldix.net/foo.html?asdf=bar").canonical.should == "net.pauldix/foo.html?asdf=bar"
|
19
|
+
Domainatrix.parse("http://foo.pauldix.net").canonical.should == "net.pauldix.foo"
|
20
|
+
Domainatrix.parse("http://foo.bar.pauldix.net").canonical.should == "net.pauldix.bar.foo"
|
21
|
+
Domainatrix.parse("http://pauldix.co.uk").canonical.should == "uk.co.pauldix"
|
22
|
+
end
|
15
23
|
end
|
16
24
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: f1sherman-domainatrix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 11
|
10
|
+
version: 0.0.11
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Paul Dix
|