Permalink
Browse files

assignment on LocationCoordinate

  • Loading branch information...
1 parent adccbf6 commit 28226b93df408768e1375c9fd32cec407cb2fb0f @weibel committed Jun 21, 2012
Showing with 37 additions and 6 deletions.
  1. +21 −5 motion/core_location_data_types.rb
  2. +16 −1 spec/core_location_data_types_spec.rb
@@ -9,24 +9,40 @@ class LocationCoordinate
# LocationCoordinate.new(1,2)
# LocationCoordinate.new([1,2])
- # CoordinateSpan.new(CLLocationCoordinate2D)
+ # LocationCoordinate.new(LocationCoordinate)
+ # LocationCoordinate.new(CLLocationCoordinate2D)
def initialize(*args)
+ latitude, longitude = nil, nil
args.flatten!
- if args.first.is_a?(CLLocationCoordinate2D)
- @sdk = args.first
- else
- @sdk = CLLocationCoordinate2DMake(args[0], args[1])
+ if args.size == 1
+ arg = args.first
+ if arg.is_a?(CLLocationCoordinate2D)
+ latitude, longitude = arg.latitude, arg.longitude
+ elsif arg.is_a?(LocationCoordinate)
+ latitude, longitude = arg.sdk.latitude, arg.sdk.longitude
+ end
+ elsif args.size == 2
+ latitude, longitude = args[0], args[1]
end
+ @sdk = CLLocationCoordinate2DMake(latitude, longitude)
end
def latitude
@sdk.latitude
end
+ def latitude=(latitude)
+ @sdk.latitude = latitude
+ end
+
def longitude
@sdk.longitude
end
+ def longitude=(longitude)
+ @sdk.longitude = longitude
+ end
+
def to_array
[latitude, longitude]
end
@@ -3,7 +3,8 @@
lc_1 = CoreLocation::DataTypes::LocationCoordinate.new(5, 8)
lc_2 = CoreLocation::DataTypes::LocationCoordinate.new([5, 8])
lc_3 = CoreLocation::DataTypes::LocationCoordinate.new(CLLocationCoordinate2DMake(5, 8))
- @array = [lc_1, lc_2, lc_3]
+ lc_4 = CoreLocation::DataTypes::LocationCoordinate.new(lc_3)
+ @array = [lc_1, lc_2, lc_3, lc_4]
end
it 'should return the latitude' do
@@ -12,12 +13,26 @@
end
end
+ it 'should assign the latitude' do
+ @array.each do |lc|
+ lc.latitude = 10
+ lc.latitude.should.equal 10
+ end
+ end
+
it 'should return the longitude' do
@array.each do |lc|
lc.longitude.should.equal 8
end
end
+ it 'should assign the longitude' do
+ @array.each do |lc|
+ lc.longitude = 10
+ lc.longitude.should.equal 10
+ end
+ end
+
it 'should return an array' do
@array.each do |lc|
lc.to_array.should.equal [5, 8]

0 comments on commit 28226b9

Please sign in to comment.