addressabler 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
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
- begin
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('.'),
@@ -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: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Flip Sasser