diff --git a/lib/normalic/address.rb b/lib/normalic/address.rb index 7acf0d5..e6f0ee5 100644 --- a/lib/normalic/address.rb +++ b/lib/normalic/address.rb @@ -74,11 +74,7 @@ def line1 end def ==(other) - if self.to_s == other.to_s - true - else - false - end + self.to_s == other.to_s ? true : false end def match_essential?(other) diff --git a/lib/normalic/phone_number.rb b/lib/normalic/phone_number.rb index 28697db..86e0bea 100644 --- a/lib/normalic/phone_number.rb +++ b/lib/normalic/phone_number.rb @@ -43,11 +43,7 @@ def []=(field_name, value) end def ==(other) - if self.to_s == other.to_s - true - else - false - end + self.to_s == other.to_s ? true : false end end end diff --git a/lib/normalic/uri.rb b/lib/normalic/uri.rb index 7642f52..45ed9fc 100644 --- a/lib/normalic/uri.rb +++ b/lib/normalic/uri.rb @@ -93,11 +93,16 @@ def []=(field_name, value) end def ==(other) - if self.to_s == other.to_s - true - else - false - end + self.to_s == other.to_s ? true : false + end + + def match_essential?(other) + return false unless tld == other.tld + return false unless domain == other.domain + return false unless subdomain == other.subdomain || + (subdomain == 'www' && !other.subdomain) || + (!subdomain && other.subdomain == 'www') + true end private diff --git a/spec/normalic_spec.rb b/spec/normalic_spec.rb index 1ef38e4..06d93d8 100644 --- a/spec/normalic_spec.rb +++ b/spec/normalic_spec.rb @@ -60,6 +60,24 @@ uri[:query_hash].should == nil uri[:fragment].should == nil end + + it "should match_essential? a nil subdomain against a 'www' subdomain" do + uri1 = Normalic::URI.parse("http://www.github.com") + uri2 = Normalic::URI.parse("http://github.com") + uri1.match_essential?(uri2).should == true + end + + it "should match_essential? using the subdomain, domain, and tld" do + uri1 = Normalic::URI.parse("http://www.hyperpublic.com") + uri2 = Normalic::URI.parse("http://oxcart.hyperpublic.com") + uri1.match_essential?(uri2).should == false + end + + it "should match_essential? using ONLY the subdomain, domain, and tld" do + uri1 = Normalic::URI.parse("http://www.hyperpublic.com/placesplus") + uri2 = Normalic::URI.parse("http://www.hyperpublic.com/deals") + uri1.match_essential?(uri2).should == true + end end