lat_long 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 69381c0358752786e2b7b54d35982c1ab53e0ec2
4
+ data.tar.gz: bed50f54c59007998f8bcf9293603f702efb30b7
5
+ SHA512:
6
+ metadata.gz: 09cccfbb22ca309b58f058e8164849f95c97d22a0fdb8fe61686d6c33126414e5d80eeeec68bf0e424cd5be211b80e1a3404bf04a35a184905659896401a90b3
7
+ data.tar.gz: f9df1234412cfeaeef77ca7346ac62f7c8d714a9665a1b021a6d586417ed65855402dc5c6be1c112c29cbf932e81fe2c0e0ddb1be0e4ade22d191fc508960884
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .byebug_history
2
+ *.gem
data/.reek ADDED
@@ -0,0 +1,5 @@
1
+ IrresponsibleModule:
2
+ enabled: false
3
+
4
+ TooManyStatements:
5
+ max_statements: 12
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at matis@craftedcode.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lat_long.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,61 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ lat_long (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.3.0)
10
+ axiom-types (0.1.1)
11
+ descendants_tracker (~> 0.0.4)
12
+ ice_nine (~> 0.11.0)
13
+ thread_safe (~> 0.3, >= 0.3.1)
14
+ byebug (9.0.6)
15
+ codeclimate-engine-rb (0.3.1)
16
+ virtus (~> 1.0)
17
+ coercible (1.0.0)
18
+ descendants_tracker (~> 0.0.1)
19
+ descendants_tracker (0.0.4)
20
+ thread_safe (~> 0.3, >= 0.3.1)
21
+ equalizer (0.0.11)
22
+ ice_nine (0.11.2)
23
+ minitest (5.10.1)
24
+ parser (2.3.1.2)
25
+ ast (~> 2.2)
26
+ powerpack (0.1.1)
27
+ rainbow (2.1.0)
28
+ rake (10.5.0)
29
+ reek (4.1.0)
30
+ codeclimate-engine-rb (~> 0.3.1)
31
+ parser (~> 2.3.1, >= 2.3.1.2)
32
+ rainbow (~> 2.0)
33
+ rubocop (0.41.1)
34
+ parser (>= 2.3.1.1, < 3.0)
35
+ powerpack (~> 0.1)
36
+ rainbow (>= 1.99.1, < 3.0)
37
+ ruby-progressbar (~> 1.7)
38
+ unicode-display_width (~> 1.0, >= 1.0.1)
39
+ ruby-progressbar (1.8.1)
40
+ thread_safe (0.3.6)
41
+ unicode-display_width (1.1.0)
42
+ virtus (1.0.5)
43
+ axiom-types (~> 0.1)
44
+ coercible (~> 1.0)
45
+ descendants_tracker (~> 0.0, >= 0.0.3)
46
+ equalizer (~> 0.0, >= 0.0.9)
47
+
48
+ PLATFORMS
49
+ ruby
50
+
51
+ DEPENDENCIES
52
+ bundler (~> 1.11)
53
+ byebug (~> 9.0)
54
+ lat_long!
55
+ minitest (~> 5.0)
56
+ rake (~> 10.0)
57
+ reek (~> 4.1)
58
+ rubocop (~> 0.41)
59
+
60
+ BUNDLED WITH
61
+ 1.11.2
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Matis Masters
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/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Matis Masters
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,102 @@
1
+ # LatLong
2
+
3
+ ## short-FAQ
4
+ ### What does this gem do?
5
+
6
+ Move `lat, long` points based on distance and direction.
7
+
8
+ ### What else?
9
+
10
+ For now it's just that, you can check the [Usage](#usage) part for details
11
+
12
+ ### What is it for?
13
+
14
+ I developed it, and use it, to create fake data for my tests when doing mobile
15
+ apps that depend on location based stuff. Things like `people 500 meters away`,
16
+ `people within a certain radius`, and similar.
17
+
18
+ I would love to hear about it if you find a better use for it.
19
+
20
+ ### IMPORTANT NOTE
21
+
22
+ ```
23
+ There are several ways of calculating distances using geo-coordinates. The different
24
+ approaches vary in accuracy, and are used in different scenarios. This gem uses
25
+ the [Aviation Formula](http://www.edwilliams.org/avform.htm),
26
+ it is the simplest of them all, but it might have big errors
27
+ margins when used with distances over 2km. I'm ok with this for now.
28
+ ```
29
+
30
+ ### Future?
31
+
32
+ I'm planning on understanding (first things first), and implementing all the other
33
+ formulas, so they can be used when needed, or otherwise having the gem automatically
34
+ pick the more accurate depending on the parameters `lat, long, distance, direction`.
35
+
36
+ Check [Github Issues](https://github.com/matismasters/lat_long/issues) for backlog
37
+ and progress.
38
+
39
+ ## Installation
40
+
41
+ Add this line to your application's Gemfile:
42
+
43
+ ```ruby
44
+ gem 'lat_long'
45
+ ```
46
+
47
+ And then execute:
48
+
49
+ $ bundle
50
+
51
+ Or install it yourself as:
52
+
53
+ $ gem install lat_long
54
+
55
+ ## Usage
56
+
57
+ Simply tell distance, distance_unit, direction and get a new location hash
58
+
59
+ ```ruby
60
+
61
+ require 'lat_long'
62
+
63
+ washington_ave_and_17st_nw = LatLong::Point.new 38.892133, (-77.039498)
64
+
65
+ new_location = washington_ave_and_17st_nw.move 250, :meters, :north
66
+
67
+ new_location[:lat] # 38.892133
68
+ new_location[:long] # -77.033727
69
+
70
+ ```
71
+
72
+ Valid directions:
73
+
74
+ - `:west`
75
+ - `:north_west`
76
+ - `:north`
77
+ - `:north_east`
78
+ - `:east`
79
+ - `:south_east`
80
+ - `:south`
81
+ - `:south_west`
82
+
83
+ Valid distance units:
84
+
85
+ - `:meters`
86
+ - `:kilometers`
87
+ - `:miles`
88
+ - `:feet`
89
+
90
+ ## Development
91
+
92
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
93
+
94
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
95
+
96
+ ## Contributing
97
+
98
+ Bug reports and pull requests are welcome on GitHub at https://github.com/matismasters/lat_long. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
99
+
100
+ ## License
101
+
102
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+ require 'rubocop/rake_task'
4
+ require 'reek/rake/task'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ end
11
+
12
+ RuboCop::RakeTask.new :rubocop do |t|
13
+ t.options = ['--display-cop-names']
14
+ end
15
+
16
+ Reek::Rake::Task.new do |t|
17
+ t.fail_on_error = true
18
+ end
19
+
20
+ task :default => [:test, :rubocop, :reek]
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "lat_long"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lat_long.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'lat_long/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "lat_long"
8
+ spec.version = LatLong::VERSION
9
+ spec.authors = ["Matis Masters"]
10
+ spec.email = ["me@matis.io"]
11
+
12
+ spec.summary = %q{Move Lat, Long, coordinates using distance and direction.}
13
+ spec.description = %q{LatLong::Point.new(32.000, -41.000).move(5, :miles, :north) => [lat: 32.333, long: -41.000]}
14
+ spec.homepage = "https://github.com/matismasters/lat_long"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "minitest", "~> 5.0"
25
+ spec.add_development_dependency "byebug", "~> 9.0"
26
+ spec.add_development_dependency "rubocop", "~> 0.41"
27
+ spec.add_development_dependency "reek", "~> 4.1"
28
+ end
data/lib/lat_long.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'lat_long/version'
2
+ require 'lat_long/constants'
3
+ require 'lat_long/point'
@@ -0,0 +1,21 @@
1
+ module LatLong
2
+ DIRECTION_MULTIPLIERS = {
3
+ west: { y_axis: 0, x_axis: -1 },
4
+ north_west: { y_axis: 1, x_axis: -1 },
5
+ north: { y_axis: 1, x_axis: 0 },
6
+ north_east: { y_axis: 1, x_axis: 1 },
7
+ east: { y_axis: 0, x_axis: 1 },
8
+ south_east: { y_axis: -1, x_axis: 1 },
9
+ south: { y_axis: -1, x_axis: 0 },
10
+ south_west: { y_axis: -1, x_axis: -1 },
11
+ }.freeze
12
+
13
+ TO_METERS_MULTIPLIERS = {
14
+ meters: 1,
15
+ kilometers: 1000,
16
+ miles: 0.000621371,
17
+ feet: 3.28084
18
+ }.freeze
19
+
20
+ EARTH_RADIUS = 6378137.freeze
21
+ end
@@ -0,0 +1,51 @@
1
+ module LatLong
2
+ class Point
3
+ ARGUMENT_ERRORS_TEXT = {
4
+ direction:
5
+ 'direction argument is not supported, use any of the following ' +
6
+ DIRECTION_MULTIPLIERS.keys.join(', '),
7
+ distance_unit:
8
+ 'distance unit argument not supported, use any of the following ' +
9
+ TO_METERS_MULTIPLIERS.keys.join(', '),
10
+ }.freeze
11
+
12
+ attr_reader :lat, :long
13
+
14
+ def initialize(lat, long)
15
+ @lat = lat
16
+ @long = long
17
+ end
18
+
19
+ def starting_point
20
+ [@lat, @long]
21
+ end
22
+
23
+ def move(raw_distance, unit, direction)
24
+ direction = direction_multipliers(direction)
25
+ distance = distance_in_meters(raw_distance, unit)
26
+
27
+ lat_offset = distance / EARTH_RADIUS
28
+ long_offset = distance / (
29
+ EARTH_RADIUS * Math.cos(Math::PI * @lat/180)
30
+ )
31
+
32
+ new_point_lat = @lat + (lat_offset * 180/Math::PI) * direction[:y_axis]
33
+ new_point_long = @long + (long_offset * 180/Math::PI) * direction[:x_axis]
34
+
35
+ { lat: new_point_lat, long: new_point_long }
36
+ end
37
+
38
+ private
39
+
40
+ def direction_multipliers(direction)
41
+ DIRECTION_MULTIPLIERS[direction] ||
42
+ raise(ArgumentError, ARGUMENT_ERRORS_TEXT[:direction])
43
+ end
44
+
45
+ def distance_in_meters(distance, unit)
46
+ unit_multiplier = TO_METERS_MULTIPLIERS[unit] ||
47
+ raise(ArgumentError, ARGUMENT_ERRORS_TEXT[:distance_unit])
48
+ distance.to_f * unit_multiplier
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,3 @@
1
+ module LatLong
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lat_long
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matis Masters
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-05-04 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
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: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '9.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '9.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.41'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.41'
83
+ - !ruby/object:Gem::Dependency
84
+ name: reek
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '4.1'
97
+ description: 'LatLong::Point.new(32.000, -41.000).move(5, :miles, :north) => [lat:
98
+ 32.333, long: -41.000]'
99
+ email:
100
+ - me@matis.io
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".reek"
107
+ - CODE_OF_CONDUCT.md
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - LICENSE
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - bin/console
115
+ - bin/setup
116
+ - lat_long.gemspec
117
+ - lib/lat_long.rb
118
+ - lib/lat_long/constants.rb
119
+ - lib/lat_long/point.rb
120
+ - lib/lat_long/version.rb
121
+ homepage: https://github.com/matismasters/lat_long
122
+ licenses:
123
+ - MIT
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.5.1
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: Move Lat, Long, coordinates using distance and direction.
145
+ test_files: []