Skip to content

Commit

Permalink
Add Twitter::Place#contained_within and Twitter::Place#contained_within?
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Jul 28, 2013
1 parent afe8663 commit 23cc247
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/twitter/place.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ def bounding_box?
!bounding_box.nil?
end

def contained_within
new_or_null_object(Twitter::Place, :contained_within)
end

# @return [Boolean]
def contained_within?
!contained_within.nil?
end
alias contained? contained_within?

# @return [String]
def country_code
@country_code ||= @attrs[:country_code] || @attrs[:countryCode]
Expand Down
24 changes: 23 additions & 1 deletion spec/twitter/place_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
end

describe "#bounding_box" do
it "returns a Twitter::Place when bounding_box is set" do
it "returns a Twitter::Geo when bounding_box is set" do
place = Twitter::Place.new(:id => "247f43d441defc03", :bounding_box => {:type => "Polygon", :coordinates => [[[-122.40348192, 37.77752898], [-122.387436, 37.77752898], [-122.387436, 37.79448597], [-122.40348192, 37.79448597]]]})
expect(place.bounding_box).to be_a Twitter::Geo::Polygon
end
Expand All @@ -42,6 +42,28 @@
end
end

describe "#contained_within" do
it "returns a Twitter::Place when contained_within is set" do
place = Twitter::Place.new(:id => "247f43d441defc03", :contained_within => {:id => "247f43d441defc04"})
expect(place.contained_within).to be_a Twitter::Place
end
it "returns nil when not contained_within is not set" do
place = Twitter::Place.new(:id => "247f43d441defc03")
expect(place.contained_within).to be_nil
end
end

describe "#contained_within?" do
it "returns true when contained_within is set" do
place = Twitter::Place.new(:id => "247f43d441defc03", :contained_within => {:id => "247f43d441defc04"})
expect(place.contained?).to be_true
end
it "returns false when contained_within is not set" do
place = Twitter::Place.new(:id => "247f43d441defc03")
expect(place.contained?).to be_false
end
end

describe "#country_code" do
it "returns a country code when set with country_code" do
place = Twitter::Place.new(:id => "247f43d441defc03", :country_code => "US")
Expand Down

0 comments on commit 23cc247

Please sign in to comment.