cartier 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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cartier.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Patrick Jones
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.
@@ -0,0 +1,32 @@
1
+ # Cartier
2
+
3
+ Cartier is a gem used to simplify some common GPS type calcuations from a current project I've been working on.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'cartier'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install cartier
18
+
19
+ ## Usage
20
+
21
+ After installation one will need to create at minimum two instances of the Cartier::GPSLocation type.
22
+ For example, the CN Tower location would be created as such: cn_tower = Cartier::GPSLocation.new("43.64775237227008", "-79.38707828521729")
23
+ To determine the distance between two locations: Cartier::Navigation.haversine_distance(cn_tower, ago)
24
+
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/cartier/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Patrick Jones"]
6
+ gem.email = ["patrick@patrickjones.ca"]
7
+ gem.description = %q{Cartier is a gem to be used to simply dealing with GPS data calculations such as distance, location, and bearing.}
8
+ gem.summary = %q{Cartier is a gem to be used to simply dealing with GPS data calculations such as distance, location, and bearing.}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "cartier"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Cartier::VERSION
17
+ gem.add_development_dependency "rspec"
18
+ gem.add_development_dependency "factory_girl"
19
+ end
@@ -0,0 +1,7 @@
1
+ require "cartier/version"
2
+ require "cartier/navigation"
3
+ require "cartier/gps_location"
4
+
5
+ module Cartier
6
+
7
+ end
@@ -0,0 +1,24 @@
1
+ module Cartier
2
+ class GPSLocation
3
+ attr_accessor :latitude, :longitude, :decimal_notation, :imperial
4
+ #
5
+ #
6
+ # * *Args* :
7
+ # - +latitude+ -> Latitude in Degree Notation (i.e. 37.0428759)
8
+ # - +longitude+ -> Longitude in Degree Notation (i.e. 37.0428759)
9
+ # - +decimal_notation+ -> Defaulting to true for now
10
+ # - +imperial+ -> Defaulting to Imperial system instead of metric (for now)
11
+ # * *Returns* :
12
+ # - a GPSLocation object
13
+ # * *Raises* :
14
+ # - ++ ->
15
+ #
16
+ def initialize(latitude=nil, longitude=nil, decimal_notation=true, imperial=true)
17
+ self.latitude = latitude
18
+ self.longitude = longitude
19
+ self.decimal_notation = decimal_notation
20
+ self.imperial = imperial
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,62 @@
1
+ module Cartier
2
+
3
+ # Encapsulating class for Navigation calculations
4
+ class Navigation
5
+ EARTH_RADIUS = 6371
6
+
7
+ #
8
+ #
9
+ # * *Args* :
10
+ # - +location+ -> GPSLocation object representing current location
11
+ # - +longitude+ -> GPSLocation object representing current destination
12
+ # * *Returns* :
13
+ # - distance in miles
14
+
15
+ def self.haversine_distance(location, destination)
16
+ delta_lat = (destination.latitude.to_f - location.latitude.to_f) * Math::PI/180
17
+ delta_long = (destination.longitude.to_f - location.longitude.to_f) * Math::PI/180
18
+
19
+ latitude_1 = (location.latitude.to_f) * Math::PI/180
20
+ latitude_2 = (destination.latitude.to_f) * Math::PI/180
21
+
22
+ a = Math.sin(delta_lat/2)**2 + Math.sin(delta_long/2)**2 * Math.cos(latitude_1) * Math.cos(latitude_2)
23
+ c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a))
24
+ EARTH_RADIUS * c
25
+ end
26
+
27
+ #
28
+ #
29
+ # * *Args* :
30
+ # - +location_here+ -> GPSLocation object representing current location
31
+ # - +array_of_locations+ -> an Array of GPSLocation objects
32
+ # * *Returns* :
33
+ # - GPSLocation object representing closest location
34
+ #
35
+ def self.closest_point(location_here, array_of_locations=nil)
36
+ array_of_locations.sort do |a, b|
37
+ self.haversine_distance(location_here, a) <=> self.haversine_distance(location_here, b)
38
+ end.first
39
+ end
40
+
41
+ #
42
+ #
43
+ # * *Args* :
44
+ # - +location+ -> GPSLocation object representing current location
45
+ # - +destination+ -> GPSLocation object representing destination
46
+ # * *Returns* :
47
+ # - Bearing in Degrees (not radians)
48
+ #
49
+ def self.get_bearing(location, destination)
50
+ location_long = location.longitude.to_f
51
+ location_latitude = location.latitude.to_f
52
+ destination_long = destination.longitude.to_f
53
+ destination_latitude = destination.latitude.to_f
54
+
55
+ delta_long = (destination_long - location_long)
56
+ y = Math.sin(delta_long) * Math.cos(destination_latitude)
57
+ x = Math.cos(location_latitude) * Math.sin(destination_latitude) - Math.sin(location_latitude) * Math.cos(destination_latitude) * Math.cos(delta_long)
58
+ (Math.atan2(y, x) / Math::PI) * 180
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,3 @@
1
+ module Cartier
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,8 @@
1
+
2
+ describe "Cartier" do
3
+
4
+ it "should exist and function" do
5
+ Cartier.should be_a Module
6
+ end
7
+
8
+ end
@@ -0,0 +1,25 @@
1
+ require 'factory_girl'
2
+
3
+ FactoryGirl.define do
4
+
5
+ factory :cn_tower, class: Cartier::GPSLocation do |f|
6
+ f.latitude "43.64775237227008"
7
+ f.longitude "-79.38707828521729"
8
+ end
9
+
10
+ factory :ago, class: Cartier::GPSLocation do
11
+ latitude "43.653476"
12
+ longitude "-79.392686"
13
+ end
14
+
15
+ factory :washington_monument, class: Cartier::GPSLocation do
16
+ latitude "38.89514125082739"
17
+ longitude "-77.03527450561523"
18
+ end
19
+
20
+ factory :union_station, class: Cartier::GPSLocation do
21
+ latitude "38.897102"
22
+ longitude "-77.006355"
23
+ end
24
+
25
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+ require 'factories/location_factory'
3
+
4
+ include Cartier
5
+
6
+ describe "Cartier::GPSLocation" do
7
+
8
+ it "GPSLocation should build correctly" do
9
+ @location = FactoryGirl.build(:cn_tower)
10
+ @location.latitude.should == "43.64775237227008"
11
+ @location.longitude.should == "-79.38707828521729"
12
+ end
13
+
14
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+ require 'factories/location_factory'
3
+
4
+ include Cartier
5
+
6
+ describe Cartier::Navigation do
7
+ it "distance to self should be 0.0" do
8
+ @location = FactoryGirl.build(:cn_tower)
9
+ Cartier::Navigation.haversine_distance(@location, @location).should == 0.0
10
+ end
11
+
12
+ it "distance to washington monument should not be zero" do
13
+ @cn_tower = FactoryGirl.build(:cn_tower)
14
+ @washington_monument = FactoryGirl.build(:washington_monument)
15
+ Cartier::Navigation.haversine_distance(@cn_tower, @washington_monument).should == 563.7658958719776
16
+ end
17
+
18
+ it ".closest_point should find the closest point" do
19
+ @here = FactoryGirl.build(:cn_tower)
20
+ @ago = FactoryGirl.build(:ago)
21
+ @washington_monument = FactoryGirl.build(:washington_monument)
22
+ Cartier::Navigation.closest_point(@here, [@ago, @washington_monument]).should == @ago
23
+ end
24
+
25
+ it ".get_bearing should calculate the bearing between cn_tower and ago properly" do
26
+ @here = FactoryGirl.build(:cn_tower)
27
+ @ago = FactoryGirl.build(:ago)
28
+ Cartier::Navigation.get_bearing(@here, @ago).should == -42.86284026213279
29
+ end
30
+
31
+ it ".get_bearing should calculate the bearing between two points" do
32
+ @here = FactoryGirl.build(:cn_tower)
33
+ @ago = FactoryGirl.build(:washington_monument)
34
+ Cartier::Navigation.get_bearing(@here, @ago).should == 18.121412196238214
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'cartier'
4
+ require 'rspec'
5
+ require 'factory_girl'
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cartier
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Patrick Jones
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
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: factory_girl
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
+ description: Cartier is a gem to be used to simply dealing with GPS data calculations
47
+ such as distance, location, and bearing.
48
+ email:
49
+ - patrick@patrickjones.ca
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE
57
+ - README.md
58
+ - Rakefile
59
+ - cartier.gemspec
60
+ - lib/cartier.rb
61
+ - lib/cartier/gps_location.rb
62
+ - lib/cartier/navigation.rb
63
+ - lib/cartier/version.rb
64
+ - spec/cartier_spec.rb
65
+ - spec/factories/location_factory.rb
66
+ - spec/gps_location_spec.rb
67
+ - spec/naviation_spec.rb
68
+ - spec/spec_helper.rb
69
+ homepage: ''
70
+ licenses: []
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 1.8.24
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: Cartier is a gem to be used to simply dealing with GPS data calculations
93
+ such as distance, location, and bearing.
94
+ test_files:
95
+ - spec/cartier_spec.rb
96
+ - spec/factories/location_factory.rb
97
+ - spec/gps_location_spec.rb
98
+ - spec/naviation_spec.rb
99
+ - spec/spec_helper.rb