locapoint 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,2 @@
1
+ Version 0.0.1 (October 21, 2006)
2
+ * First release.
data/MIT-LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2006 Yohji Shidara
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,27 @@
1
+ = LocaPoint conversion library for Ruby
2
+
3
+ A ruby library for conversion between LocaPoint and latitude/longuitude notation.
4
+
5
+ == What is LocaPoint?
6
+
7
+ LocaPoint is the state-of-the-art location pointer that can express any location of the world, only with 12 letters.
8
+ (quoted from http://www.locapoint.com)
9
+
10
+ == Examples
11
+
12
+ Locapoint.decode("SD9.XC4.ER9.CY4")
13
+ > [35.6586477189174, 139.745663667239]
14
+
15
+ Locapoint.encode(35.658648,139.745664)
16
+ > "SD9.XC4.ER9.CY4"
17
+
18
+ == See Also
19
+
20
+ * LocaPoint Official Site: http://www.locapoint.com
21
+ * LocaPoint Specifications: http://www.locapoint.com/en/spec.html
22
+
23
+ == Author
24
+
25
+ Copyright (c) 2006 Yohji Shidara, under MIT License.
26
+
27
+ Yohji Shidara <dara@shidara.net>
data/Rakefile ADDED
@@ -0,0 +1,85 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ require 'rake/testtask'
5
+ require 'rake/packagetask'
6
+ require 'rake/gempackagetask'
7
+ require 'rake/rdoctask'
8
+ require 'rake/contrib/rubyforgepublisher'
9
+ require 'fileutils'
10
+ include FileUtils
11
+ require File.join(File.dirname(__FILE__), 'lib', 'locapoint', 'version')
12
+
13
+ AUTHOR = "shidara"
14
+ EMAIL = "dara@shidara.net"
15
+ DESCRIPTION = "LocaPoint conversion library"
16
+ RUBYFORGE_PROJECT = "locapoint"
17
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
18
+ BIN_FILES = %w( )
19
+
20
+
21
+ NAME = "locapoint"
22
+ REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
23
+ VERS = ENV['VERSION'] || (Locapoint::VERSION::STRING + (REV ? ".#{REV}" : ""))
24
+ CLEAN.include ['**/.*.sw?', '*.gem', '.config']
25
+ RDOC_OPTS = ['--quiet', '--title', "locapoint documentation",
26
+ "--opname", "index.html",
27
+ "--line-numbers",
28
+ "--main", "README",
29
+ "--inline-source"]
30
+
31
+ desc "Packages up locapoint gem."
32
+ task :default => [:test]
33
+ task :package => [:clean]
34
+
35
+ Rake::TestTask.new("test") { |t|
36
+ t.libs << "test"
37
+ t.pattern = "test/**/*_test.rb"
38
+ t.verbose = true
39
+ }
40
+
41
+ spec =
42
+ Gem::Specification.new do |s|
43
+ s.name = NAME
44
+ s.version = VERS
45
+ s.platform = Gem::Platform::RUBY
46
+ s.has_rdoc = true
47
+ s.extra_rdoc_files = ["README", "CHANGELOG"]
48
+ s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
49
+ s.summary = DESCRIPTION
50
+ s.description = DESCRIPTION
51
+ s.author = AUTHOR
52
+ s.email = EMAIL
53
+ s.homepage = HOMEPATH
54
+ s.executables = BIN_FILES
55
+ s.rubyforge_project = RUBYFORGE_PROJECT
56
+ s.bindir = "bin"
57
+ s.require_path = "lib"
58
+ s.autorequire = "locapoint"
59
+
60
+ #s.add_dependency('activesupport', '>=1.3.1')
61
+ #s.required_ruby_version = '>= 1.8.2'
62
+
63
+ s.files = %w(README CHANGELOG MIT-LICENSE Rakefile) +
64
+ Dir.glob("{bin,doc,test,lib,templates,generator,extras,website,script}/**/*") +
65
+ Dir.glob("ext/**/*.{h,c,rb}") +
66
+ Dir.glob("examples/**/*.rb") +
67
+ Dir.glob("tools/*.rb")
68
+
69
+ # s.extensions = FileList["ext/**/extconf.rb"].to_a
70
+ end
71
+
72
+ Rake::GemPackageTask.new(spec) do |p|
73
+ p.need_tar = true
74
+ p.gem_spec = spec
75
+ end
76
+
77
+ task :install do
78
+ name = "#{NAME}-#{VERS}.gem"
79
+ sh %{rake package}
80
+ sh %{sudo gem install pkg/#{name}}
81
+ end
82
+
83
+ task :uninstall => [:clean] do
84
+ sh %{sudo gem uninstall #{NAME}}
85
+ end
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'locapoint'
3
+
4
+ p Locapoint.decode("SD9.XC4.ER9.CY4")
5
+ p Locapoint.encode(35.658648,139.745664)
@@ -0,0 +1,61 @@
1
+ =begin
2
+ LocaPoint Conversion Library for Ruby
3
+ Copyright (c) 2006 Yohji Shidara, under MIT License
4
+ =end
5
+
6
+ # LocaPoint module.
7
+ module Locapoint
8
+ # Regular expression that matches LocaPoint strings.
9
+ LOCAPOINT_REGEXP = /[A-Z][A-Z][0-9]\.[A-Z][A-Z][0-9]\.[A-Z][A-Z][0-9]\.[A-Z][A-Z][0-9]/
10
+
11
+ # Exception thrown by LocaPoint format errors.
12
+ class FormatError < Exception; end
13
+
14
+ # Will convert a LocaPoint string into a pair of +latitude+ and +longitude+.
15
+ def decode(locapoint)
16
+ unless locapoint =~ LOCAPOINT_REGEXP && locapoint.size == 15
17
+ raise FormatError, "Invalid format"
18
+ end
19
+
20
+ s = locapoint.to_s
21
+ latitude = ((s[0] - ?A) * 1757600 \
22
+ +(s[1] - ?A) * 67600 \
23
+ +(s[2] - ?0) * 6760 \
24
+ +(s[8] - ?A) * 260 \
25
+ +(s[9] - ?A) * 10 \
26
+ +(s[10] - ?0) ) * 180 / 45697600.0 -90;
27
+ longitude = ((s[4] - ?A) * 1757600 \
28
+ +(s[5] - ?A) * 67600 \
29
+ +(s[6] - ?0) * 6760 \
30
+ +(s[12] - ?A) * 260 \
31
+ +(s[13] - ?A) * 10 \
32
+ +(s[14] - ?0) ) * 360 / 45697600.0 -180;
33
+ return latitude, longitude
34
+ end
35
+
36
+ # Will convert latitude and longitude into LocaPoint string.
37
+ def encode(latitude, longitude)
38
+ latitude_step = (latitude.to_f + 90) / 180 * 45697600;
39
+ longitude_step = (longitude.to_f + 180) / 360 * 45697600;
40
+
41
+ s = "AA0.AA0.AA0.AA0"
42
+ s[0] += (latitude_step / 1757600 % 26).to_i
43
+ s[1] += (latitude_step / 67600 % 26).to_i
44
+ s[2] += (latitude_step / 6760 % 10).to_i
45
+
46
+ s[4] += (longitude_step / 1757600 % 26).to_i
47
+ s[5] += (longitude_step / 67600 % 26).to_i
48
+ s[6] += (longitude_step / 6760 % 10).to_i
49
+
50
+ s[8] += (latitude_step / 260 % 26).to_i
51
+ s[9] += (latitude_step / 10 % 26).to_i
52
+ s[10] += (latitude_step / 1 % 10).to_i
53
+
54
+ s[12] += (longitude_step / 260 % 26).to_i
55
+ s[13] += (longitude_step / 10 % 26).to_i
56
+ s[14] += (longitude_step / 1 % 10).to_i
57
+
58
+ return s
59
+ end
60
+ module_function :decode, :encode
61
+ end
@@ -0,0 +1,9 @@
1
+ module Locapoint #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ TINY = 1
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
data/lib/locapoint.rb ADDED
@@ -0,0 +1 @@
1
+ Dir[File.join(File.dirname(__FILE__), 'locapoint/**/*.rb')].sort.each { |lib| require lib }
@@ -0,0 +1,23 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class LocapointTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_decodeing
9
+ lat,lon = Locapoint.decode("SD9.XC4.ER9.CY4")
10
+ assert_in_delta( 35.658648, lat, 1e-6)
11
+ assert_in_delta(139.745664, lon, 1e-6)
12
+ end
13
+
14
+ def test_decodeing_of_invalid_string
15
+ assert_raise(Locapoint::FormatError) {
16
+ Locapoint.decode("Hello World.")
17
+ }
18
+ end
19
+
20
+ def test_encoding
21
+ assert_equal("SD9.XC4.ER9.CY4", Locapoint.encode(35.658648,139.745664))
22
+ end
23
+ end
@@ -0,0 +1,2 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/locapoint'
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: locapoint
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.1
7
+ date: 2006-10-21 00:00:00 +09:00
8
+ summary: LocaPoint conversion library
9
+ require_paths:
10
+ - lib
11
+ email: dara@shidara.net
12
+ homepage: http://locapoint.rubyforge.org
13
+ rubyforge_project: locapoint
14
+ description: LocaPoint conversion library
15
+ autorequire: locapoint
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - shidara
31
+ files:
32
+ - README
33
+ - CHANGELOG
34
+ - MIT-LICENSE
35
+ - Rakefile
36
+ - test/locapoint_test.rb
37
+ - test/test_helper.rb
38
+ - lib/locapoint
39
+ - lib/locapoint.rb
40
+ - lib/locapoint/locapoint.rb
41
+ - lib/locapoint/version.rb
42
+ - examples/example.rb
43
+ test_files: []
44
+
45
+ rdoc_options:
46
+ - --quiet
47
+ - --title
48
+ - locapoint documentation
49
+ - --opname
50
+ - index.html
51
+ - --line-numbers
52
+ - --main
53
+ - README
54
+ - --inline-source
55
+ - --exclude
56
+ - ^(examples|extras)/
57
+ extra_rdoc_files:
58
+ - README
59
+ - CHANGELOG
60
+ executables: []
61
+
62
+ extensions: []
63
+
64
+ requirements: []
65
+
66
+ dependencies: []
67
+