gpsutils 0.1.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/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.1.0
5
+ before_install: gem install bundler -v 1.12.3
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem "codeclimate-test-reporter", group: :test, require: nil
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Ronnie Mose
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # GpsUtils
2
+
3
+ [![Build Status](https://travis-ci.org/megamoose/gpsutils.svg?branch=master)](https://travis-ci.org/megamoose/gpsutils)
4
+ [![Code Climate](https://codeclimate.com/github/megamoose/gpsutils/badges/gpa.svg)](https://codeclimate.com/github/megamoose/gpsutils)
5
+ [![Test Coverage](https://codeclimate.com/github/megamoose/gpsutils/badges/coverage.svg)](https://codeclimate.com/github/megamoose/gpsutils/coverage)
6
+
7
+ Small ruby library for working with GPS coordinates.
8
+
9
+ ## Contents
10
+ - [Installation](#installation)
11
+ - [Using Bundler with rubygems](#using-bundler-with-rubygems)
12
+ - [Using Bundler with github](#using-bundler-with-github)
13
+ - [Using locally build gem-file](#using-locally-build-gem-file)
14
+ - [Usage](#usage)
15
+ - [License](#license)
16
+
17
+ ## Installation
18
+
19
+ You can install the package from rubygems or github using Bundler or create your own package from the source code.
20
+
21
+ ### Using Bundler with rubygems
22
+
23
+ Edit you Gemfile and add the following line:
24
+ ```ruby
25
+ gem 'gpsutils'
26
+ ```
27
+
28
+ Then run:
29
+ ```bash
30
+ $ bundle install
31
+ ```
32
+
33
+ ### Using Bundler with github
34
+
35
+ Edit you Gemfile and add the following line:
36
+ ```ruby
37
+ gem 'gpsutils', :git => 'https://github.com/megamoose/gpsutils.git'
38
+ ```
39
+
40
+ Then run:
41
+ ```bash
42
+ $ bundle install
43
+ ```
44
+
45
+ ### Using locally build gem-file
46
+
47
+ Clone the repository from github:
48
+
49
+ ```bash
50
+ $ git clone https://github.com/megamoose/gpsutils.git gpsutils
51
+ $ cd gpsutils
52
+ ```
53
+
54
+ Build the gem-file:
55
+
56
+ ```bash
57
+ $ gem build gpsutils.gemspec
58
+ ```
59
+
60
+ Install the gem-file:
61
+
62
+ ```bash
63
+ $ gem install gpsutils-*.gem
64
+ ```
65
+
66
+ ## Usage
67
+
68
+ Determine whether or not a given location (point) is within an area (bounding box):
69
+
70
+ ```ruby
71
+ # Follow instructions in the installation section.
72
+ require 'gpsutils'
73
+
74
+ # Latitude, Longitude.
75
+ location = GpsUtils::Point.new(-22.955776, -43.536438)
76
+
77
+ # North-West corner.
78
+ nw = GpsUtils::Point.new(-22.746120, -43.795060)
79
+ # South-East corner.
80
+ se = GpsUtils::Point.new(-23.076347, -43.101608)
81
+
82
+ # North-West point, South-East point.
83
+ area = GpsUtils::BoundingBox.new(nw, se)
84
+
85
+ area.cover? location
86
+ ```
87
+
88
+ ## License
89
+ This code is free to use under the terms of the [MIT license](LICENSE).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/gpsutils.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gpsutils/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gpsutils"
8
+ spec.version = GpsUtils::VERSION
9
+ spec.authors = ["Ronnie Mose"]
10
+
11
+ spec.summary = "Small ruby library for working with GPS coordinates."
12
+ spec.description = "Small ruby library for working with GPS coordinates."
13
+ spec.homepage = "https://github.com/megamoose/gpsutils"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.12"
20
+ spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_development_dependency "rspec", "~> 3.0"
22
+ end
@@ -0,0 +1,3 @@
1
+ module GpsUtils
2
+ VERSION = "0.1.1"
3
+ end
data/lib/gpsutils.rb ADDED
@@ -0,0 +1,55 @@
1
+ module GpsUtils
2
+
3
+ class Point
4
+ attr_accessor :lat, :lng
5
+
6
+ def initialize(lat, lng)
7
+ unless lat.is_a? Float or lat.is_a? Integer
8
+ raise ArgumentError.new 'lat must be float or integer.'
9
+ end
10
+
11
+ unless lng.is_a? Float or lng.is_a? Integer
12
+ raise ArgumentError.new 'lng must be float or integer.'
13
+ end
14
+
15
+ @lat = lat
16
+ @lng = lng
17
+ end
18
+
19
+ def to_a
20
+ [@lat, @lng]
21
+ end
22
+
23
+ def to_s
24
+ "#{@lat},#{@lng}"
25
+ end
26
+ end
27
+
28
+ class BoundingBox
29
+ attr_accessor :se, :nw
30
+
31
+ def initialize(nw_point, se_point)
32
+ @nw = nw_point
33
+ @se = se_point
34
+
35
+ @p21 = @se.lat - @nw.lat
36
+ @p41 = @nw.lng - @se.lng
37
+
38
+ @p21ms = @p21 ** 2
39
+ @p41ms = @p41 ** 2
40
+ end
41
+
42
+ def cover?(point)
43
+ return false if @nw.lat == @se.lat and @nw.lng == @se.lng
44
+
45
+ p = [point.lat - @nw.lat, point.lng - @se.lng]
46
+
47
+ p21x = p[0] * @p21
48
+ p41x = p[1] * @p41
49
+
50
+ 0 <= p21x and p21x <= @p21ms and 0 <= p41x and p41x <= @p41ms
51
+ end
52
+
53
+ end
54
+
55
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gpsutils
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Ronnie Mose
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Small ruby library for working with GPS coordinates.
56
+ email:
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - ".codeclimate.yml"
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".rubocop.yml"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - LICENSE
68
+ - README.md
69
+ - Rakefile
70
+ - gpsutils.gemspec
71
+ - lib/gpsutils.rb
72
+ - lib/gpsutils/version.rb
73
+ homepage: https://github.com/megamoose/gpsutils
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.2.1
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Small ruby library for working with GPS coordinates.
97
+ test_files: []