diff --git a/lib/twitter/place.rb b/lib/twitter/place.rb index 71726be95..42eb515d9 100644 --- a/lib/twitter/place.rb +++ b/lib/twitter/place.rb @@ -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] diff --git a/spec/twitter/place_spec.rb b/spec/twitter/place_spec.rb index 215c30483..e7b356bea 100644 --- a/spec/twitter/place_spec.rb +++ b/spec/twitter/place_spec.rb @@ -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")