Permalink
Browse files

Move Point and Polygon classes under Geo namespace

  • Loading branch information...
1 parent 3365f8a commit 059cc5545195f99ba1b484e8359b7246f29be37e @sferik committed Jul 18, 2012
View
26 lib/twitter/geo/point.rb
@@ -1,20 +1,22 @@
require 'twitter/geo'
module Twitter
- class Point < Twitter::Geo
+ class Geo
+ class Point < Twitter::Geo
- # @return [Integer]
- def latitude
- self.coordinates[0]
- end
- alias lat latitude
+ # @return [Integer]
+ def latitude
+ self.coordinates[0]
+ end
+ alias lat latitude
- # @return [Integer]
- def longitude
- self.coordinates[1]
- end
- alias long longitude
- alias lng longitude
+ # @return [Integer]
+ def longitude
+ self.coordinates[1]
+ end
+ alias long longitude
+ alias lng longitude
+ end
end
end
View
4 lib/twitter/geo/polygon.rb
@@ -1,6 +1,8 @@
require 'twitter/geo'
module Twitter
- class Polygon < Twitter::Geo
+ class Geo
+ class Polygon < Twitter::Geo
+ end
end
end
View
4 lib/twitter/geo_factory.rb
@@ -9,10 +9,10 @@ class GeoFactory
#
# @param attrs [Hash]
# @raise [ArgumentError] Error raised when supplied argument is missing a :type key.
- # @return [Twitter::Point, Twitter::Polygon]
+ # @return [Twitter::Geo::Point, Twitter::Geo::Polygon]
def self.fetch_or_new(attrs={})
if type = attrs.delete(:type)
- Twitter.const_get(type.camelize.to_sym).fetch_or_new(attrs)
+ Twitter::Geo.const_get(type.camelize.to_sym).fetch_or_new(attrs)
else
raise ArgumentError, "argument must have a :type key"
end
View
2 lib/twitter/place.rb
@@ -6,7 +6,7 @@ class Place < Twitter::Identity
attr_reader :attributes, :country, :full_name, :name, :url, :woeid
alias woe_id woeid
- # @return [Twitter::Point, Twitter::Polygon]
+ # @return [Twitter::Geo::Point, Twitter::Geo::Polygon]
def bounding_box
@bounding_box ||= Twitter::GeoFactory.fetch_or_new(@attrs[:bounding_box]) unless @attrs[:bounding_box].nil?
end
View
2 lib/twitter/status.rb
@@ -42,7 +42,7 @@ def full_text
self.retweeted_status && self.retweeted_status.user ? "RT @#{self.retweeted_status.user.screen_name}: #{self.retweeted_status.text}" : self.text
end
- # @return [Twitter::Point, Twitter::Polygon]
+ # @return [Twitter::Geo::Point, Twitter::Geo::Polygon]
def geo
@geo ||= Twitter::GeoFactory.fetch_or_new(@attrs[:geo]) unless @attrs[:geo].nil?
end
View
12 spec/twitter/geo/point_spec.rb
@@ -1,23 +1,23 @@
require 'helper'
-describe Twitter::Point do
+describe Twitter::Geo::Point do
before do
- @point = Twitter::Point.new(:coordinates => [-122.399983, 37.788299])
+ @point = Twitter::Geo::Point.new(:coordinates => [-122.399983, 37.788299])
end
describe "#==" do
it "returns false for empty objects" do
- point = Twitter::Point.new
- other = Twitter::Point.new
+ point = Twitter::Geo::Point.new
+ other = Twitter::Geo::Point.new
(point == other).should be_false
end
it "returns true when objects coordinates are the same" do
- other = Twitter::Point.new(:coordinates => [-122.399983, 37.788299])
+ other = Twitter::Geo::Point.new(:coordinates => [-122.399983, 37.788299])
(@point == other).should be_true
end
it "returns false when objects coordinates are different" do
- other = Twitter::Point.new(:coordinates => [37.788299, -122.399983])
+ other = Twitter::Geo::Point.new(:coordinates => [37.788299, -122.399983])
(@point == other).should be_false
end
it "returns false when classes are different" do
View
12 spec/twitter/geo/polygon_spec.rb
@@ -1,23 +1,23 @@
require 'helper'
-describe Twitter::Polygon do
+describe Twitter::Geo::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]]])
+ @polygon = Twitter::Geo::Polygon.new(:coordinates => [[[-122.40348192, 37.77752898], [-122.387436, 37.77752898], [-122.387436, 37.79448597], [-122.40348192, 37.79448597]]])
end
describe "#==" do
it "returns false for empty objects" do
- polygon = Twitter::Polygon.new
- other = Twitter::Polygon.new
+ polygon = Twitter::Geo::Polygon.new
+ other = Twitter::Geo::Polygon.new
(polygon == other).should be_false
end
it "returns true when objects coordinates are the same" do
- other = Twitter::Polygon.new(:coordinates => [[[-122.40348192, 37.77752898], [-122.387436, 37.77752898], [-122.387436, 37.79448597], [-122.40348192, 37.79448597]]])
+ other = Twitter::Geo::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 "returns false when objects coordinates are different" do
- other = Twitter::Polygon.new(:coordinates => [[[37.77752898, -122.40348192], [37.77752898, -122.387436], [37.79448597, -122.387436], [37.79448597, -122.40348192]]])
+ other = Twitter::Geo::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
it "returns false when classes are different" do
View
4 spec/twitter/geo_factory_spec.rb
@@ -5,11 +5,11 @@
describe ".new" do
it "generates a Point" do
geo = Twitter::GeoFactory.fetch_or_new(:type => 'Point')
- geo.should be_a Twitter::Point
+ geo.should be_a Twitter::Geo::Point
end
it "generates a Polygon" do
geo = Twitter::GeoFactory.fetch_or_new(:type => 'Polygon')
- geo.should be_a Twitter::Polygon
+ geo.should be_a Twitter::Geo::Polygon
end
it "raises an ArgumentError when type is not specified" do
lambda do
View
2 spec/twitter/geo_spec.rb
@@ -21,7 +21,7 @@
(@geo == other).should be_false
end
it "returns false when classes are different" do
- other = Twitter::Polygon.new(:coordinates => [[[-122.40348192, 37.77752898], [-122.387436, 37.77752898], [-122.387436, 37.79448597], [-122.40348192, 37.79448597]]])
+ other = Twitter::Geo::Polygon.new(:coordinates => [[[-122.40348192, 37.77752898], [-122.387436, 37.77752898], [-122.387436, 37.79448597], [-122.40348192, 37.79448597]]])
(@geo == other).should be_false
end
end
View
2 spec/twitter/place_spec.rb
@@ -23,7 +23,7 @@
describe "#bounding_box" do
it "returns a Twitter::Place when 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]]]})
- place.bounding_box.should be_a Twitter::Polygon
+ place.bounding_box.should be_a Twitter::Geo::Polygon
end
it "returns nil when not set" do
place = Twitter::Place.new(:id => "247f43d441defc03")
View
4 spec/twitter/status_spec.rb
@@ -92,9 +92,9 @@
end
describe "#geo" do
- it "returns a Twitter::Point when set" do
+ it "returns a Twitter::Geo::Point when set" do
status = Twitter::Status.new(:id => 28669546014, :geo => {:id => 1, :type => 'Point'})
- status.geo.should be_a Twitter::Point
+ status.geo.should be_a Twitter::Geo::Point
end
it "returns nil when not set" do
status = Twitter::Status.new(:id => 28669546014)

0 comments on commit 059cc55

Please sign in to comment.