chsh-lat_lng 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2009-09-16
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
data/Manifest.txt ADDED
@@ -0,0 +1,6 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ lib/lat_lng.rb
6
+ test/test_lat_lng.rb
data/README.txt ADDED
@@ -0,0 +1,47 @@
1
+ = lat_lng
2
+
3
+ * http://github.com/chsh/latlng
4
+
5
+ == DESCRIPTION:
6
+
7
+ A simple class for manipulate geographical point.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * include WGS84 SRID.
12
+ * convert point to some formats.
13
+
14
+ == SYNOPSIS:
15
+
16
+ require 'lat_lng'
17
+
18
+ == REQUIREMENTS:
19
+
20
+ * GeoRuby
21
+
22
+ == INSTALL:
23
+
24
+ * gem i chsh-lat_lng
25
+
26
+ == LICENSE:
27
+
28
+ Copyright (c) 2009 CHIKURA Shinsaku <scene.sc@gmail.com>
29
+
30
+ Permission is hereby granted, free of charge, to any person obtaining
31
+ a copy of this software and associated documentation files (the
32
+ 'Software'), to deal in the Software without restriction, including
33
+ without limitation the rights to use, copy, modify, merge, publish,
34
+ distribute, sublicense, and/or sell copies of the Software, and to
35
+ permit persons to whom the Software is furnished to do so, subject to
36
+ the following conditions:
37
+
38
+ The above copyright notice and this permission notice shall be
39
+ included in all copies or substantial portions of the Software.
40
+
41
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
42
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
43
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
44
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
45
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
46
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
47
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ Hoe.spec 'lat_lng' do
7
+ developer('CHIKURA Shinsaku', 'scene.sc@gmail.com')
8
+
9
+ # self.rubyforge_name = 'lat_lngx' # if different than 'lat_lng'
10
+ end
11
+
12
+ # vim: syntax=ruby
data/lib/lat_lng.rb ADDED
@@ -0,0 +1,84 @@
1
+ class LatLng
2
+ VERSION = '0.0.1'
3
+ attr_reader :lat, :lng, :srid
4
+
5
+ WGS84 = 4326
6
+ SRID = WGS84
7
+
8
+ def initialize(lat, lng, srid = WGS84)
9
+ @lat = lat.to_f
10
+ @lng = lng.to_f
11
+ @srid = srid.to_i
12
+ end
13
+
14
+ def self.from(object)
15
+ case object
16
+ when LatLng
17
+ object
18
+ when GeoRuby::SimpleFeatures::Point
19
+ self.from_point(object)
20
+ when String
21
+ self.from_string(object)
22
+ when Array
23
+ LatLng.new(*object)
24
+ when nil
25
+ nil
26
+ else
27
+ raise "Unsupported parameter class: #{object.class}"
28
+ end
29
+ end
30
+
31
+ def ==(target)
32
+ return false unless target.is_a? LatLng
33
+ return true if @lat == target.lat && @lng == target.lng && @srid == target.srid
34
+ false
35
+ end
36
+
37
+ def self.from_point(point)
38
+ return nil unless point
39
+ LatLng.new(point.y, point.x, point.srid)
40
+ end
41
+
42
+ def self.from_string(point_string, srid = WGS84)
43
+ pss = point_string.strip
44
+ values = pss.split(/\s*,\s*/)
45
+ if values.size == 1
46
+ values = pss.split(/\s+/)
47
+ end
48
+ LatLng.new(values[0], values[1], srid)
49
+ end
50
+
51
+ def +(latlng)
52
+ raise "srid mismatch #{self.srid} != #{latlng.srid}" unless self.srid == latlng.srid
53
+ LatLng.new(@lat + latlng.lat, @lng + latlng.lng)
54
+ end
55
+
56
+ def -(latlng)
57
+ raise "srid mismatch #{self.srid} != #{latlng.srid}" unless self.srid == latlng.srid
58
+ LatLng.new(@lat - latlng.lat, @lng - latlng.lng)
59
+ end
60
+
61
+ def *(value)
62
+ LatLng.new(@lat * value, @lng * value)
63
+ end
64
+
65
+ def /(value)
66
+ LatLng.new(@lat / value, @lng / value)
67
+ end
68
+
69
+ def point
70
+ GeoRuby::SimpleFeatures::Point.from_x_y(@lng.to_f, @lat.to_f, @srid)
71
+ end
72
+
73
+ def as_text(opts = {})
74
+ opts.reverse_merge! :blank => true
75
+ "#{@lat},#{' ' if opts[:blank]}#{@lng}"
76
+ end
77
+
78
+ def lon
79
+ @lng
80
+ end
81
+ def to_s
82
+ as_text(:blank => false)
83
+ end
84
+ end
@@ -0,0 +1,8 @@
1
+ require "test/unit"
2
+ require "lat_lng"
3
+
4
+ class TestLatLng < Test::Unit::TestCase
5
+ def test_sanity
6
+ flunk "write tests or I will kneecap you"
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chsh-lat_lng
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - CHIKURA Shinsaku
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-16 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.3.3
24
+ version:
25
+ description: A simple class for manipulate geographical point.
26
+ email:
27
+ - scene.sc@gmail.com
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - History.txt
34
+ - Manifest.txt
35
+ - README.txt
36
+ files:
37
+ - History.txt
38
+ - Manifest.txt
39
+ - README.txt
40
+ - Rakefile
41
+ - lib/lat_lng.rb
42
+ - test/test_lat_lng.rb
43
+ has_rdoc: false
44
+ homepage: http://github.com/chsh/latlng
45
+ licenses:
46
+ post_install_message:
47
+ rdoc_options:
48
+ - --main
49
+ - README.txt
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project: lat_lng
67
+ rubygems_version: 1.3.5
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: A simple class for manipulate geographical point.
71
+ test_files:
72
+ - test/test_lat_lng.rb