geo_position 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +19 -0
- data/.rspec.sample +2 -0
- data/.rvmrc.sample +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +52 -0
- data/Rakefile +1 -0
- data/geo_position.gemspec +24 -0
- data/lib/geo_position.rb +14 -0
- data/lib/geo_position/conversion.rb +4 -0
- data/lib/geo_position/conversion/dms.rb +80 -0
- data/lib/geo_position/parser.rb +4 -0
- data/lib/geo_position/version.rb +3 -0
- data/reload_yard +3 -0
- data/spec/conversion/dms_spec.rb +94 -0
- data/spec/spec_helper.rb +20 -0
- metadata +134 -0
data/.gitignore
ADDED
data/.rspec.sample
ADDED
data/.rvmrc.sample
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use --install --create 1.9.3@geo_position
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Nate Klaiber
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# GeoPosition
|
2
|
+
|
3
|
+
A simple utility to allow you to convert DMS (Degrees, Minutes, Seconds)
|
4
|
+
to a latitude and longitude. The initial driver for this utility was
|
5
|
+
working on an application that took Geo Position information from EXIF
|
6
|
+
data.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'geo_position'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install geo_position
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Usage is very simple right now:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
conversion = GeoPosition::Conversion::Dms.new(12,3,42.2,'w')
|
28
|
+
|
29
|
+
conversion.to_s
|
30
|
+
=> "12 deg 3' 42.2\" W"
|
31
|
+
|
32
|
+
conversion.to_f
|
33
|
+
=> -12.061783333333333
|
34
|
+
```
|
35
|
+
|
36
|
+
The only requirement is that you pass in a valid direction of N, S, E,
|
37
|
+
or W. Everything else will be coerced to a float.
|
38
|
+
|
39
|
+
## Todo
|
40
|
+
|
41
|
+
* Add ability to parse from the EXIF string and extract into the
|
42
|
+
conversion object
|
43
|
+
* Add ability to convert from lat/lon to DMS
|
44
|
+
* Add simple methods in the root object to handle conversions
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
1. Fork it
|
49
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
50
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
51
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
52
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'geo_position/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "geo_position"
|
8
|
+
gem.version = GeoPosition::VERSION
|
9
|
+
gem.authors = ["Nate Klaiber"]
|
10
|
+
gem.email = ["nate@theklaibers.com"]
|
11
|
+
gem.description = %q{ A gem that handles conversion between Decimal/Hours/Seconds and Latitude/Longitude }
|
12
|
+
gem.summary = %q{ Converting between Deciman/Hours/Seconds and Latitude/Longitude }
|
13
|
+
gem.homepage = "https://github.com/archivability/geo_position"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rake'
|
21
|
+
gem.add_development_dependency 'rspec'
|
22
|
+
gem.add_development_dependency 'yard'
|
23
|
+
gem.add_development_dependency 'redcarpet'
|
24
|
+
end
|
data/lib/geo_position.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
root = File.expand_path(File.dirname(__FILE__))
|
2
|
+
|
3
|
+
# Version
|
4
|
+
require File.join(root, 'geo_position', 'version')
|
5
|
+
|
6
|
+
# Conversions
|
7
|
+
require File.join(root, 'geo_position', 'conversion')
|
8
|
+
require File.join(root, 'geo_position', 'conversion', 'dms')
|
9
|
+
|
10
|
+
# Parsers
|
11
|
+
require File.join(root, 'geo_position', 'parser')
|
12
|
+
|
13
|
+
module GeoPosition
|
14
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module GeoPosition
|
2
|
+
module Conversion
|
3
|
+
# This is the main class that will perform the conversion from
|
4
|
+
# Degrees, Minutes, and Seconds
|
5
|
+
#
|
6
|
+
# @example
|
7
|
+
# conversion = GeoPosition::Conversion::Dms.new(12,3,42.2,'w')
|
8
|
+
#
|
9
|
+
# conversion.to_s
|
10
|
+
# => 12 deg 3' 42.2" W
|
11
|
+
#
|
12
|
+
# conversion.to_f
|
13
|
+
# => -12.061783333333333
|
14
|
+
#
|
15
|
+
class Dms
|
16
|
+
# Error that is raised if invalid directions are provided
|
17
|
+
InvalidDirectionError = Class.new(StandardError)
|
18
|
+
|
19
|
+
ALLOWED_DIRECTIONS = %w( N n E e S s W w )
|
20
|
+
MINUTES_CONVERSION = 60
|
21
|
+
SECONDS_CONVERSION = 3600
|
22
|
+
|
23
|
+
# Creates a new instance of the DMS conversion object
|
24
|
+
#
|
25
|
+
# @param degrees [String,Integer]
|
26
|
+
# @param minutes [String,Integer]
|
27
|
+
# @param seconds [String,Integer]
|
28
|
+
# @param direction [String] The direction
|
29
|
+
#
|
30
|
+
# @return [void]
|
31
|
+
def initialize(degrees, minutes, seconds, direction)
|
32
|
+
raise InvalidDirectionError.new("Please provided a direction of N, S, E, or W") unless valid_direction?(direction)
|
33
|
+
|
34
|
+
@degrees = degrees
|
35
|
+
@minutes = minutes
|
36
|
+
@seconds = seconds
|
37
|
+
|
38
|
+
@direction = direction
|
39
|
+
end
|
40
|
+
|
41
|
+
def degrees
|
42
|
+
@degrees.to_f
|
43
|
+
end
|
44
|
+
|
45
|
+
def minutes
|
46
|
+
@minutes.to_f
|
47
|
+
end
|
48
|
+
|
49
|
+
def seconds
|
50
|
+
@seconds.to_f
|
51
|
+
end
|
52
|
+
|
53
|
+
def direction
|
54
|
+
@direction.to_s.upcase
|
55
|
+
end
|
56
|
+
|
57
|
+
def to_s
|
58
|
+
"%s deg %s' %s\" %s" % [self.degrees.to_i, self.minutes.to_i, self.seconds, self.direction]
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_f
|
62
|
+
convert!
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
def valid_direction?(dir)
|
67
|
+
ALLOWED_DIRECTIONS.include?(dir[0,1])
|
68
|
+
end
|
69
|
+
|
70
|
+
def convert!
|
71
|
+
result = (self.degrees + ((self.minutes/MINUTES_CONVERSION) + (self.seconds/SECONDS_CONVERSION)))
|
72
|
+
if negative? then -(result) else result end
|
73
|
+
end
|
74
|
+
|
75
|
+
def negative?
|
76
|
+
self.direction == 'S' || self.direction == 'W'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/reload_yard
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
# With negative numbers
|
2
|
+
# With nil
|
3
|
+
# With empty strings
|
4
|
+
# With strings
|
5
|
+
require 'spec_helper'
|
6
|
+
|
7
|
+
describe GeoPosition::Conversion::Dms do
|
8
|
+
subject { described_class.new(12,3,42.42,'w') }
|
9
|
+
|
10
|
+
it "responds to #to_f" do
|
11
|
+
subject.should respond_to(:to_f)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "responds to #to_s" do
|
15
|
+
subject.should respond_to(:to_s)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "raises an exception if invalid direction is given" do
|
19
|
+
lambda { described_class.new(12,12,23,'r') }.should raise_error(GeoPosition::Conversion::Dms::InvalidDirectionError)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "coerces the degrees to a float" do
|
23
|
+
subject.degrees.should eql(12.0)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "coerces the minutes to a float" do
|
27
|
+
subject.minutes.should eql(3.0)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "coerces the seconds to a float" do
|
31
|
+
subject.seconds.should eql(42.42)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "upcases the direction" do
|
35
|
+
gp = described_class.new(12,12,12,'n')
|
36
|
+
gp.direction.should == 'N'
|
37
|
+
end
|
38
|
+
|
39
|
+
it "returns the formatted string" do
|
40
|
+
subject.to_s.should == "12 deg 3' 42.42\" W"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "returns the floated conversion" do
|
44
|
+
subject.to_f.should eql(-12.061783333333333)
|
45
|
+
end
|
46
|
+
|
47
|
+
context("North") do
|
48
|
+
subject { described_class.new(12,3,42.42,'n') }
|
49
|
+
|
50
|
+
it "returns the formatted string" do
|
51
|
+
subject.to_s.should == "12 deg 3' 42.42\" N"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "returns the floated conversion" do
|
55
|
+
subject.to_f.should eql(12.061783333333333)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context("East") do
|
60
|
+
subject { described_class.new(12,3,42.42,'e') }
|
61
|
+
|
62
|
+
it "returns the formatted string" do
|
63
|
+
subject.to_s.should == "12 deg 3' 42.42\" E"
|
64
|
+
end
|
65
|
+
|
66
|
+
it "returns the floated conversion" do
|
67
|
+
subject.to_f.should eql(12.061783333333333)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context("South") do
|
72
|
+
subject { described_class.new(12,3,42.42,'s') }
|
73
|
+
|
74
|
+
it "returns the formatted string" do
|
75
|
+
subject.to_s.should == "12 deg 3' 42.42\" S"
|
76
|
+
end
|
77
|
+
|
78
|
+
it "returns the floated conversion" do
|
79
|
+
subject.to_f.should eql(-12.061783333333333)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context("West") do
|
84
|
+
subject { described_class.new(12,3,42.42,'w') }
|
85
|
+
|
86
|
+
it "returns the formatted string" do
|
87
|
+
subject.to_s.should == "12 deg 3' 42.42\" W"
|
88
|
+
end
|
89
|
+
|
90
|
+
it "returns the floated conversion" do
|
91
|
+
subject.to_f.should eql(-12.061783333333333)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
#
|
7
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
8
|
+
require File.join(File.dirname(__FILE__), '../lib/geo_position')
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
12
|
+
config.run_all_when_everything_filtered = true
|
13
|
+
#config.filter_run :focus
|
14
|
+
|
15
|
+
# Run specs in random order to surface order dependencies. If you find an
|
16
|
+
# order dependency and want to debug it, you can fix the order by providing
|
17
|
+
# the seed, which is printed after each run.
|
18
|
+
# --seed 1234
|
19
|
+
config.order = 'random'
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: geo_position
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nate Klaiber
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: yard
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: redcarpet
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: ! ' A gem that handles conversion between Decimal/Hours/Seconds and Latitude/Longitude '
|
79
|
+
email:
|
80
|
+
- nate@theklaibers.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- .rspec.sample
|
87
|
+
- .rvmrc.sample
|
88
|
+
- Gemfile
|
89
|
+
- LICENSE.txt
|
90
|
+
- README.md
|
91
|
+
- Rakefile
|
92
|
+
- geo_position.gemspec
|
93
|
+
- lib/geo_position.rb
|
94
|
+
- lib/geo_position/conversion.rb
|
95
|
+
- lib/geo_position/conversion/dms.rb
|
96
|
+
- lib/geo_position/parser.rb
|
97
|
+
- lib/geo_position/version.rb
|
98
|
+
- reload_yard
|
99
|
+
- spec/conversion/dms_spec.rb
|
100
|
+
- spec/spec_helper.rb
|
101
|
+
homepage: https://github.com/archivability/geo_position
|
102
|
+
licenses: []
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ! '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
segments:
|
114
|
+
- 0
|
115
|
+
hash: -4563760366661124322
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ! '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
segments:
|
123
|
+
- 0
|
124
|
+
hash: -4563760366661124322
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 1.8.24
|
128
|
+
signing_key:
|
129
|
+
specification_version: 3
|
130
|
+
summary: Converting between Deciman/Hours/Seconds and Latitude/Longitude
|
131
|
+
test_files:
|
132
|
+
- spec/conversion/dms_spec.rb
|
133
|
+
- spec/spec_helper.rb
|
134
|
+
has_rdoc:
|