geo_point 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -3,7 +3,7 @@ h1. Geo Point
3
3
  Adds the concept of a GeoPoint for geo libraries. A GeoPoint encapsulates latitude and longitude, and:
4
4
 
5
5
  * a coordinates mode (coord_mode) that can be set to either :lng_lat or :lat_lng
6
- * calculations such as distance, bearing, midpoint etc.
6
+ * calculations such as: distance_to, bearing_to, midpoint, intersection and destination point
7
7
  * parsing from various String, Hash or Array formats, including from DMS string format, such as "58 38 38N, 003 04 12W"
8
8
 
9
9
  Using GeoPoints makes it much easier and more efficient to transport location point data and various geo libraries adds additional functionality such as
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
data/geo_point.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{geo_point}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Kristian Mandrup}]
12
- s.date = %q{2011-06-13}
12
+ s.date = %q{2011-06-14}
13
13
  s.description = %q{Allows for easy parsing of Strings, Hashes and Arrays into a GeoPoint with lat/long}
14
14
  s.email = %q{kmandrup@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
31
31
  "lib/geo_point/core_extension.rb",
32
32
  "lib/geo_point/shared.rb",
33
33
  "spec/geo_point/class_methods_spec.rb",
34
+ "spec/geo_point/coord_mode_spec.rb",
34
35
  "spec/geo_point/initializer_spec.rb",
35
36
  "spec/geo_point/lat_lon.rb",
36
37
  "spec/geo_point_spec.rb",
@@ -14,3 +14,34 @@ end
14
14
  cls.send :include, GeoPoint::CoreExtension
15
15
  end
16
16
 
17
+ class Array
18
+ def to_lat
19
+ raise "Array must contain at least one element to return the latitude" if empty?
20
+ case GeoPoint.coord_mode
21
+ when :lng_lat
22
+ self[1].to_lat
23
+ else
24
+ first.to_lat
25
+ end
26
+ end
27
+
28
+ def to_lng
29
+ raise "Array must contain at least two elements to return the longitude" if !self[1]
30
+ case GeoPoint.coord_mode
31
+ when :lng_lat
32
+ first.to_lng
33
+ else
34
+ self[1].to_lng
35
+ end
36
+ end
37
+
38
+ def to_lat_lng
39
+ raise "Array must contain at least two elements to be converted to latitude and longitude" if !(size >= 2)
40
+ [first.to_lat, self[1].to_lng]
41
+ end
42
+
43
+ def to_lng_lat
44
+ to_lat_lng.reverse
45
+ # [first.to_lng, self[1].to_lat]
46
+ end
47
+ end
data/lib/geo_point.rb CHANGED
@@ -29,8 +29,8 @@ class GeoPoint
29
29
  # - :mode - coordinates mode, either :lng_lat or :lat_lng, otherwise uses global setting as per GeoPoint.coord_mode
30
30
  def initialize *args
31
31
  options = args.is_a?(GeoPoint) ? {} : args.last_option
32
- earth_radius_km = options[:radius]
33
- coord_mode = options[:mode]
32
+ earth_radius_km = options[:radius] if options[:radius]
33
+ coord_mode = options[:mode] if options[:mode]
34
34
 
35
35
  case args.size
36
36
  when 1
@@ -127,12 +127,15 @@ class GeoPoint
127
127
  end
128
128
 
129
129
  def to_coords points
130
- points.send(:"to_#{coord_mode}")
130
+ meth = :"to_#{coord_mode}"
131
+ points.send(meth)
131
132
  end
132
133
 
133
134
  def create_from_one args
134
- args = args.first
135
- create_from_two *to_coords(args)
135
+ args = args.first
136
+ array = to_coords(args)
137
+ array = coord_mode == :lng_lat ? array.reverse : array
138
+ create_from_two *array
136
139
  end
137
140
 
138
141
  def create_from_two lat, lon
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ # - www.movable-type.co.uk/scripts/latlong.html
4
+ describe GeoPoint do
5
+ describe '#coord_mode' do
6
+ it 'should parse as lng, lat' do
7
+ GeoPoint.coord_mode = :lng_lat
8
+ point = [2, 5].geo_point
9
+ point.lat.should == 5
10
+ point.lng.should == 2
11
+ end
12
+
13
+ it 'should parse as lat, lng' do
14
+ GeoPoint.coord_mode = :lat_lng
15
+ point = [5, 2].geo_point
16
+ point.lat.should == 5
17
+ point.lng.should == 2
18
+ end
19
+ end
20
+ end
21
+
22
+ describe Array do
23
+ describe '#coord_mode' do
24
+ it 'should parse as lng, lat' do
25
+ GeoPoint.coord_mode = :lng_lat
26
+ [2, 5].to_lat.should == 5
27
+ [2, 5].to_lng.should == 2
28
+ end
29
+
30
+ it 'should parse as lat, lng' do
31
+ GeoPoint.coord_mode = :lat_lng
32
+ [5, 2].to_lat.should == 5
33
+ [5, 2].to_lng.should == 2
34
+ end
35
+ end
36
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geo_point
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-06-13 00:00:00.000000000Z
12
+ date: 2011-06-14 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: geo_calc
16
- requirement: &2153026520 !ruby/object:Gem::Requirement
16
+ requirement: &2156168400 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.7.3
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2153026520
24
+ version_requirements: *2156168400
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: geo_units
27
- requirement: &2153024900 !ruby/object:Gem::Requirement
27
+ requirement: &2156165340 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.2.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2153024900
35
+ version_requirements: *2156165340
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &2153023220 !ruby/object:Gem::Requirement
38
+ requirement: &2156164180 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.6.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2153023220
46
+ version_requirements: *2156164180
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
- requirement: &2153021760 !ruby/object:Gem::Requirement
49
+ requirement: &2156162640 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.0.6
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2153021760
57
+ version_requirements: *2156162640
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: jeweler
60
- requirement: &2153019700 !ruby/object:Gem::Requirement
60
+ requirement: &2156160060 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.6.2
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2153019700
68
+ version_requirements: *2156160060
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rcov
71
- requirement: &2153018380 !ruby/object:Gem::Requirement
71
+ requirement: &2156156320 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2153018380
79
+ version_requirements: *2156156320
80
80
  description: Allows for easy parsing of Strings, Hashes and Arrays into a GeoPoint
81
81
  with lat/long
82
82
  email: kmandrup@gmail.com
@@ -100,6 +100,7 @@ files:
100
100
  - lib/geo_point/core_extension.rb
101
101
  - lib/geo_point/shared.rb
102
102
  - spec/geo_point/class_methods_spec.rb
103
+ - spec/geo_point/coord_mode_spec.rb
103
104
  - spec/geo_point/initializer_spec.rb
104
105
  - spec/geo_point/lat_lon.rb
105
106
  - spec/geo_point_spec.rb
@@ -119,7 +120,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
120
  version: '0'
120
121
  segments:
121
122
  - 0
122
- hash: 1472290565497148887
123
+ hash: -646464585705380862
123
124
  required_rubygems_version: !ruby/object:Gem::Requirement
124
125
  none: false
125
126
  requirements: