Permalink
Browse files

core_ext spec passes

  • Loading branch information...
1 parent c6ab1b9 commit 7ec43d158755c9bb850958d0734be1c5374cdcdd @kristianmandrup committed Jun 11, 2011
View
@@ -1,6 +1,7 @@
source "http://rubygems.org"
gem "require_all", "~> 1.2.0"
+gem "sugar-high", "~> 0.4.5.2"
# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
View
@@ -1,2 +1,2 @@
-require 'geo_units'
require 'geo_calc/geo_point'
+require 'geo_units'
View
@@ -1,27 +1,26 @@
module GeoCalc
autoload :PrettyPrint, 'geo_calc/pretty_print'
-
- module Calc
- end
end
-module GeoCalc::Calc
- autoload :Bearing, 'geo_calc/calc/bearing'
- autoload :Destination, 'geo_calc/calc/destination'
- autoload :Distance, 'geo_calc/calc/distance'
- autoload :Intersection, 'geo_calc/calc/intersection'
- autoload :Midpoint, 'geo_calc/calc/midpoint'
- autoload :Rhumb, 'geo_calc/calc/rhumb'
+module GeoCalc
+ module Calc
+ autoload :Bearing, 'geo_calc/calc/bearing'
+ autoload :Destination, 'geo_calc/calc/destination'
+ autoload :Distance, 'geo_calc/calc/distance'
+ autoload :Intersection, 'geo_calc/calc/intersection'
+ autoload :Midpoint, 'geo_calc/calc/midpoint'
+ autoload :Rhumb, 'geo_calc/calc/rhumb'
- module All
- def self.included base
- base.send :include, GeoCalc::Calc::Bearing
- base.send :include, GeoCalc::Calc::Destination
- base.send :include, GeoCalc::Calc::Distance
- base.send :include, GeoCalc::Calc::Intersection
- base.send :include, GeoCalc::Calc::Midpoint
- base.send :include, GeoCalc::Calc::Rhumb
- base.send :include, GeoCalc::PrettyPrint
- end
- end
+ module All
+ def self.included base
+ base.send :include, GeoCalc::Calc::Bearing
+ base.send :include, GeoCalc::Calc::Destination
+ base.send :include, GeoCalc::Calc::Distance
+ base.send :include, GeoCalc::Calc::Intersection
+ base.send :include, GeoCalc::Calc::Midpoint
+ base.send :include, GeoCalc::Calc::Rhumb
+ base.send :include, GeoCalc::PrettyPrint
+ end
+ end
+ end
end
@@ -1 +1,4 @@
+require 'require_all'
+require 'geo_calc/geo_point/core_extension'
+
require_all File.dirname(__FILE__) + '/extensions'
@@ -1,5 +1,5 @@
class Array
- include GeoPoint::CoreExt
+ include ::GeoPoint::CoreExtension
def to_lat_lng
raise "Array must contain at least two elements to be converted to latitude and longitude" if !(size >= 2)
@@ -1,5 +1,5 @@
class Hash
- include GeoPoint::CoreExt
+ include GeoPoint::CoreExtension
def to_lat_lng
[to_lat, to_lng]
@@ -1,3 +1,5 @@
+require 'geo_units'
+
module GeoCalc
module NumericCheckExt
def is_numeric? arg
@@ -13,10 +15,10 @@ def check_numeric! arg
end
class Fixnum
- include GeoUnits::NumericExt
+ include ::GeoUnits::NumericExt
end
class Float
- include GeoUnits::NumericExt
+ include ::GeoUnits::NumericExt
end
View
@@ -1,5 +1,6 @@
-require 'geo_calc/geo'
+require 'sugar-high/arguments'
require 'geo_calc/calc'
+require 'geo_calc/extensions'
# Sample usage:
# p1 = GeoPoint.new(51.5136, -0.0983)
@@ -29,16 +30,15 @@ class GeoPoint
attr_reader :lat, :lon
def initialize *args
- options = last_option args
-
+ options = args.is_a?(GeoPoint) ? {} : args.last_option
earth_radius_km = options[:radius]
coord_mode = options[:mode]
-
+
case args.size
when 1
- create_from_one *args, rad
+ create_from_one args
when 2
- create_from_two *args, rad
+ create_from_two args
else
raise "GeoPoint must be initialized with either one or to arguments defining the (latitude, longitude) coordinate on the map"
end
@@ -117,14 +117,15 @@ def to_a
protected
- include NumericCheckExt
+ include ::GeoCalc::NumericCheckExt
def to_coords points
points.send(:"to_#{coord_mode}")
end
- def create_from_one points
- create_from_two to_coords(points)
+ def create_from_one args
+ args = args.first if args.is_a?(Array) && args.first.is_a?(Array)
+ create_from_two *to_coords(args)
end
def create_from_two lat, lon
@@ -1,5 +1,5 @@
class GeoPoint
- class << self
+ module ClassMethods
def earth_radius_km
@earth_radius_km ||= 6371
end
View
@@ -17,5 +17,5 @@
module GeoUnits
autoload :Converter, 'geo_units/converter'
- autoload :Numeric, 'geo_units/numeric'
+ autoload :NumericExt, 'geo_units/numeric_ext'
end
@@ -1,3 +1,6 @@
+require 'geo_calc/calc'
+require 'geo_calc/extensions'
+
module GeoUnits
module Converter
# Convert numeric degrees to deg/min/sec latitude (suffixed with N/S)
File renamed without changes.
@@ -3,56 +3,54 @@
# - www.movable-type.co.uk/scripts/latlong.html
describe GeoPoint do
describe 'ruby core Class extensions' do
- describe NumericLatLngExt do
- describe 'Fixnum extension' do
- describe '#to_lat' do
- it 'should set origin at 0,0' do
- origin = [0, 0].geo_point
- origin.lat.should == 0
- origin.lng.should == 0
- end
-
- it 'should return latitude degree value for 360' do
- 360.to_lat.should == 0
- end
-
- it 'should normalize degrees before converting to latitude, so 361 becomes 1' do
- 361.to_lat.should == 1
- end
- end
-
- describe '#to_lng' do
- it 'should return latitude degree value for 360' do
- 90.to_lng.should == 90
- end
-
- it 'should normalize degrees before converting to latitude, so 361 becomes 1' do
- 91.to_lng.should == 91
- end
- end
- end
-
- describe 'Float extension' do
- describe '#to_lat' do
- it 'should return latitude degree value for 360' do
- (360.0).to_lat.should == 0
- end
-
- it 'should normalize degrees before converting to latitude, so 361 becomes 1' do
- (361.1).to_lat.should be_within(0.01).of(1.1)
- end
- end
-
- describe '#to_lng' do
- it 'should return latitude degree value for 360' do
- (360.0).to_lng.should == 0
- end
-
- it 'should normalize degrees before converting to latitude, so 361 becomes 1' do
- (361.1).to_lng.should be_within(0.01).of(1.1)
- end
- end
- end
+ describe 'Fixnum extension' do
+ describe '#to_lat' do
+ it 'should set origin at 0,0' do
+ origin = [0, 0].geo_point
+ origin.lat.should == 0
+ origin.lng.should == 0
+ end
+
+ it 'should return latitude degree value for 360' do
+ 360.to_lat.should == 0
+ end
+
+ it 'should normalize degrees before converting to latitude, so 361 becomes 1' do
+ 361.to_lat.should == 1
+ end
+ end
+
+ describe '#to_lng' do
+ it 'should return latitude degree value for 360' do
+ 90.to_lng.should == 90
+ end
+
+ it 'should normalize degrees before converting to latitude, so 361 becomes 1' do
+ 91.to_lng.should == 91
+ end
+ end
end
- end
+
+ describe 'Float extension' do
+ describe '#to_lat' do
+ it 'should return latitude degree value for 360' do
+ (360.0).to_lat.should == 0
+ end
+
+ it 'should normalize degrees before converting to latitude, so 361 becomes 1' do
+ (361.1).to_lat.should be_within(0.01).of(1.1)
+ end
+ end
+
+ describe '#to_lng' do
+ it 'should return latitude degree value for 360' do
+ (360.0).to_lng.should == 0
+ end
+
+ it 'should normalize degrees before converting to latitude, so 361 becomes 1' do
+ (361.1).to_lng.should be_within(0.01).of(1.1)
+ end
+ end
+ end
+ end
end

0 comments on commit 7ec43d1

Please sign in to comment.