Permalink
Browse files

Add Twitter::Place#contained_within and Twitter::Place#contained_within?

  • Loading branch information...
1 parent afe8663 commit 23cc247bd20001ecbafa544bfb4546bdfc630429 @sferik committed Jul 28, 2013
Showing with 33 additions and 1 deletion.
  1. +10 −0 lib/twitter/place.rb
  2. +23 −1 spec/twitter/place_spec.rb
View
@@ -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]
View
@@ -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
@@ -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")

0 comments on commit 23cc247

Please sign in to comment.