addressabler 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/addressabler.rb +4 -5
- data/spec/addressabler_spec.rb +16 -0
- metadata +3 -3
data/lib/addressabler.rb
CHANGED
@@ -20,6 +20,7 @@ module Addressabler
|
|
20
20
|
|
21
21
|
module InstanceMethods
|
22
22
|
def domain
|
23
|
+
return nil unless host
|
23
24
|
parse_domain_parts[:domain]
|
24
25
|
end
|
25
26
|
|
@@ -36,6 +37,7 @@ module Addressabler
|
|
36
37
|
end
|
37
38
|
|
38
39
|
def subdomain
|
40
|
+
return nil unless host
|
39
41
|
parse_domain_parts[:subdomain]
|
40
42
|
end
|
41
43
|
|
@@ -44,6 +46,7 @@ module Addressabler
|
|
44
46
|
end
|
45
47
|
|
46
48
|
def tld
|
49
|
+
return nil unless host
|
47
50
|
self.class.parse_tld(host)
|
48
51
|
end
|
49
52
|
|
@@ -60,11 +63,7 @@ module Addressabler
|
|
60
63
|
|
61
64
|
def parse_domain_parts
|
62
65
|
tld = self.tld
|
63
|
-
|
64
|
-
subdomain_parts = host.gsub(/\.#{tld}$/, '').split('.')
|
65
|
-
rescue
|
66
|
-
raise host.inspect
|
67
|
-
end
|
66
|
+
subdomain_parts = host.to_s.gsub(/\.#{tld}$/, '').split('.')
|
68
67
|
@domain_parts = {
|
69
68
|
:domain => subdomain_parts.pop,
|
70
69
|
:subdomain => subdomain_parts.join('.'),
|
data/spec/addressabler_spec.rb
CHANGED
@@ -72,4 +72,20 @@ describe Addressabler do
|
|
72
72
|
uri.tld = 'co.uk'
|
73
73
|
uri.to_s.should == 'http://www.google.co.uk'
|
74
74
|
end
|
75
|
+
|
76
|
+
it "should handle things with no subdomain" do
|
77
|
+
uri = Addressable::URI.parse("http://google.com")
|
78
|
+
uri.host.should == "google.com"
|
79
|
+
uri.domain.should == "google"
|
80
|
+
uri.tld.should == "com"
|
81
|
+
uri.subdomain.should == ""
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should handle empty strings" do
|
85
|
+
uri = Addressable::URI.parse("")
|
86
|
+
uri.host.should be_nil
|
87
|
+
uri.domain.should be_nil
|
88
|
+
uri.tld.should be_nil
|
89
|
+
uri.subdomain.should be_nil
|
90
|
+
end
|
75
91
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: addressabler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Flip Sasser
|