Skip to content

Commit

Permalink
Add identity map
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Oct 9, 2011
1 parent 972f548 commit a52e0d2
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/twitter/place.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ class Place < Twitter::Base
attr_reader :attributes, :country, :country_code, :full_name, :id, :name,
:place_type, :url

def ==(other)
super || id == other.id
end

def bounding_box
Twitter::GeoFactory.new(@bounding_box) if @bounding_box
end
Expand Down
4 changes: 4 additions & 0 deletions lib/twitter/point.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ module Twitter
class Point < Twitter::Base
attr_reader :coordinates

def ==(other)
super || coordinates == other.coordinates
end

def latitude
@coordinates[0]
end
Expand Down
4 changes: 4 additions & 0 deletions lib/twitter/polygon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
module Twitter
class Polygon < Twitter::Base
attr_reader :coordinates

def ==(other)
super || coordinates == other.coordinates
end
end
end
4 changes: 4 additions & 0 deletions lib/twitter/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class Status < Twitter::Base
alias :retweeted? :retweeted
alias :truncated? :truncated

def ==(other)
super || id == other.id
end

def geo
Twitter::GeoFactory.new(@geo) if @geo
end
Expand Down
4 changes: 4 additions & 0 deletions lib/twitter/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class User < Twitter::Base
alias :show_all_inline_media? :show_all_inline_media
alias :verified? :verified

def ==(other)
super || id == other.id
end

# Get a user's status
#
# @return [Status]
Expand Down
16 changes: 16 additions & 0 deletions spec/twitter/place_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

describe Twitter::Place do

describe "#==" do

it "should return true when ids are equal" do
place = Twitter::Place.new(:id => 1)
other = Twitter::Place.new(:id => 1)
(place == other).should be_true
end

it "should return false when ids are not equal" do
place = Twitter::Place.new(:id => 1)
other = Twitter::Place.new(:id => 2)
(place == other).should be_false
end

end

describe "#bounding_box" do

it "should return a Twitter::Place when set" do
Expand Down
14 changes: 14 additions & 0 deletions spec/twitter/point_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@
@point = Twitter::Point.new(:coordinates => [-122.399983, 37.788299])
end

describe "#==" do

it "should return true when ids are equal" do
other = Twitter::Point.new(:coordinates => [-122.399983, 37.788299])
(@point == other).should be_true
end

it "should return false when ids are not equal" do
other = Twitter::Point.new(:coordinates => [37.788299, -122.399983])
(@point == other).should be_false
end

end

describe "#latitude" do

it "should return the latitude" do
Expand Down
20 changes: 20 additions & 0 deletions spec/twitter/polygon_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
describe Twitter::Polygon do

before do
@polygon = Twitter::Polygon.new(:coordinates => [[[-122.40348192, 37.77752898], [-122.387436, 37.77752898], [-122.387436, 37.79448597], [-122.40348192, 37.79448597]]])
end

describe "#==" do

it "should return true when ids are equal" do
other = Twitter::Polygon.new(:coordinates => [[[-122.40348192, 37.77752898], [-122.387436, 37.77752898], [-122.387436, 37.79448597], [-122.40348192, 37.79448597]]])
(@polygon == other).should be_true
end

it "should return false when ids are not equal" do
other = Twitter::Polygon.new(:coordinates => [[[37.77752898, -122.40348192], [37.77752898, -122.387436], [37.79448597, -122.387436], [37.79448597, -122.40348192]]])
(@polygon == other).should be_false
end

end
end
16 changes: 16 additions & 0 deletions spec/twitter/status_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

describe Twitter::Status do

describe "#==" do

it "should return true when ids are equal" do
status = Twitter::Status.new(:id => 1)
other = Twitter::Status.new(:id => 1)
(status == other).should be_true
end

it "should return false when ids are not equal" do
status = Twitter::Status.new(:id => 1)
other = Twitter::Status.new(:id => 2)
(status == other).should be_false
end

end

describe "#created_at" do

it "should return a Time when set" do
Expand Down
16 changes: 16 additions & 0 deletions spec/twitter/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

describe Twitter::User do

describe "#==" do

it "should return true when ids are equal" do
user = Twitter::User.new(:id => 1)
other = Twitter::User.new(:id => 1)
(user == other).should be_true
end

it "should return false when ids are not equal" do
user = Twitter::User.new(:id => 1)
other = Twitter::User.new(:id => 2)
(user == other).should be_false
end

end

describe "#created_at" do

it "should return a Time when created_at is set" do
Expand Down

0 comments on commit a52e0d2

Please sign in to comment.