Skip to content

Commit

Permalink
Cleanup == for all classes, wrote match_essential? for uri, wrote tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mkscrg committed Oct 24, 2011
1 parent 235fc1c commit 104c737
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
6 changes: 1 addition & 5 deletions lib/normalic/address.rb
Expand Up @@ -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)
Expand Down
6 changes: 1 addition & 5 deletions lib/normalic/phone_number.rb
Expand Up @@ -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
15 changes: 10 additions & 5 deletions lib/normalic/uri.rb
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions spec/normalic_spec.rb
Expand Up @@ -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


Expand Down

0 comments on commit 104c737

Please sign in to comment.