random-location 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZjU2YTBkNWI2MzM0ZjZjYjBjZTgyNmY5ZmZhNjg4MTk5ZDQ1OGRmMw==
5
+ data.tar.gz: !binary |-
6
+ NTY0ZTlkN2U5MTM4MmU4MjM3MTQzNmVhYjFhNDIwOTRiMWVmZjA4Mw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MGY0NGJmY2U4MjUzYzU3ZTc5NjE5ZmQzMzUwYjk4ZjlmZGVhOGI2MjhmMDc4
10
+ ZjVlNjBmNTkxZjExNGY5NmY4YmMwYzJkNjRmZGYxMTk2MjQyMjBiZjczNzUx
11
+ Njg4OGU2MzQ5YjkzODlhYWUwZTMxNmQ1NDkyMjA4YjAxNTlhZTY=
12
+ data.tar.gz: !binary |-
13
+ ZTE0OTVlMGMwYzA0ZTM1MWNhZWYwMDhhZGZhYzBhOWY1OTg5NGY3YzBhZTVi
14
+ NWExZTVhNTM4ZmYwYWRhMGE1N2NjNWYzMTMyMGI2ZDg4NGZlMmMxYjc4ZmVm
15
+ MzI4Mzc5ZmJkYWY0YjMyYzEzYTgyYTI1NTZmMTIzZGNiNzE4OWM=
@@ -0,0 +1,18 @@
1
+ .DS_Store
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in test.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Pau Pérez
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,52 @@
1
+ Random location
2
+ ===============
3
+
4
+ Description
5
+ -----------
6
+
7
+ Random location is simple tool to generate geographic coordinates randomly chosen near by the location and within the radius specified. It aims to provide a way to generate dummy data for geographical apps.
8
+
9
+ NOTE that all results are approximate values since problems derived from the shape of the earth have not been taken into consideration.
10
+
11
+
12
+ Installation
13
+ ------------
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ gem 'test'
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it like any other Ruby gem:
24
+
25
+ gem install random-location
26
+
27
+ Usage
28
+ -----
29
+ Once installed, require it:
30
+
31
+ require 'random-location'
32
+
33
+ Then, use its method specifying the coordinates of the reference point and the radius in meters
34
+
35
+ RandomLocation.near_by(41.38506, 2.17340, 10000)
36
+
37
+ It also comes with a CLI that can be used as follows:
38
+
39
+ $ random-location 41.38506 2.17340 10000
40
+ latitude = 41.41814, longitude = 2.24560
41
+
42
+
43
+ Contributing
44
+ ------------
45
+
46
+ 1. Fork it
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create new Pull Request
51
+
52
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'random-location'
4
+
5
+ raise "You must provide a latitude, longitude, radius in the stated order" if ARGV.length < 3
6
+
7
+ coords = RandomLocation.near_by(ARGV[0].to_f, ARGV[1].to_f, ARGV[2].to_i)
8
+ puts "latitude = #{'%.5f' % coords[0]}, longitude = #{'%.5f' % coords[1]}"
@@ -0,0 +1,28 @@
1
+ module RandomLocation
2
+ extend self
3
+
4
+ METERS_IN_DEGREE = 111_300
5
+
6
+ #
7
+ # returns a random location near by the one provided
8
+ # @param lat [Float] latitude
9
+ # @param lng [Float] longitude
10
+ # @param r [Integer] radius in meters
11
+ #
12
+ # @return [Array] array containing latitude and longitude of the new location
13
+ def near_by(lat, lng, r)
14
+ u = rand
15
+ v = rand
16
+
17
+ # Convert radius from meters to degrees
18
+ radius = r.to_f / METERS_IN_DEGREE
19
+
20
+ w = radius * Math.sqrt(u)
21
+ t = 2 * Math::PI * v
22
+
23
+ x = (w * Math.cos(t)) / Math.cos(lat)
24
+ y = w * Math.sin(t)
25
+
26
+ [y + lat, x + lng]
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module RandomLocation
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,22 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require "random-location/version"
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "random-location"
6
+ spec.version = RandomLocation::VERSION
7
+ spec.authors = ["Pau Pérez"]
8
+ spec.email = ["saulopefa@gmail.com"]
9
+ spec.description = "Generates geographic coordinates randomly chosen near by the location and within the radius specified. It aims to provide a way to generate dummy data for geographical apps. NOTE that all results are approximate values since problems derived from the shape of the earth have not been taken into consideration."
10
+ spec.summary = "Generates a random location nearby the one you provide"
11
+ spec.homepage = "http://github.com/sauloperez/random-location"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files`.split($/)
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.3"
20
+ spec.add_development_dependency "rake"
21
+ spec.add_development_dependency "rspec", "~> 2.14.1"
22
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe RandomLocation do
4
+
5
+ describe '#near_by' do
6
+ it 'returns an array of latitude and longitude' do
7
+ coord = RandomLocation.near_by(1, 2, 30)
8
+ expect(coord).to be_kind_of Array
9
+ expect(coord.length).to eq(2)
10
+
11
+ coord.each do |c|
12
+ expect(c).to be_kind_of(Float)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,8 @@
1
+ require_relative '../lib/random-location.rb'
2
+
3
+ RSpec.configure do |config|
4
+ config.expect_with :rspec do |c|
5
+ # disable the 'should' syntax
6
+ c.syntax = :expect
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: random-location
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Pau Pérez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-24 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '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: 2.14.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.14.1
55
+ description: Generates geographic coordinates randomly chosen near by the location
56
+ and within the radius specified. It aims to provide a way to generate dummy data
57
+ for geographical apps. NOTE that all results are approximate values since problems
58
+ derived from the shape of the earth have not been taken into consideration.
59
+ email:
60
+ - saulopefa@gmail.com
61
+ executables:
62
+ - random-location
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - .DS_Store
67
+ - .gitignore
68
+ - Gemfile
69
+ - LICENSE.txt
70
+ - README.md
71
+ - Rakefile
72
+ - bin/random-location
73
+ - lib/random-location.rb
74
+ - lib/random-location/version.rb
75
+ - random-location.gemspec
76
+ - spec/random-location_spec.rb
77
+ - spec/spec_helper.rb
78
+ homepage: http://github.com/sauloperez/random-location
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.1.11
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Generates a random location nearby the one you provide
102
+ test_files:
103
+ - spec/random-location_spec.rb
104
+ - spec/spec_helper.rb