gcmapper 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 +17 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +96 -0
- data/Rakefile +7 -0
- data/gcmapper.gemspec +20 -0
- data/lib/gcmapper.rb +18 -0
- data/lib/gcmapper/version.rb +3 -0
- data/spec/gcmapper_spec.rb +92 -0
- data/spec/spec_helper.rb +1 -0
- metadata +92 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Svilen Vassilev
|
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,96 @@
|
|
1
|
+
# GCMapper [](http://travis-ci.org/tarakanbg/gcmapper)
|
2
|
+
|
3
|
+
A Ruby gem for easy generation of Great Circle Map images between 2 or more airports.
|
4
|
+
The gem provides an API for constructing the image URLs, the maps themselves are pulled from
|
5
|
+
[gcmap.com](http://www.gcmap.com/).
|
6
|
+
|
7
|
+
The look and size of the map image can be customized by passing an optional hash of arguments, as explained
|
8
|
+
in the [Usage section](#usage).
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'gcmapper'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install gcmapper
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
The `.gcmap` method can be applied to a string (or variable containing a string), representing a valid route
|
27
|
+
between 2 or more airports (ICAO or IATA codes), connected with dashes, like this: `EGLL-LOWI` or
|
28
|
+
`LFST-LSZH-LBSF`. Here are some examples:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
# An example of normal route:
|
32
|
+
route = "EGLL-LOWI"
|
33
|
+
route.gcmap # => Returns an image map URL for the route EGLL-LOWI
|
34
|
+
|
35
|
+
# An exampmle of layover route:
|
36
|
+
another_route = "LFST-LSZH-LBSF"
|
37
|
+
another_route.gcmap # => Returns an image map URL for the layover route LFST-LSZH-LBSF
|
38
|
+
|
39
|
+
# The method can be applied directly to a string:
|
40
|
+
"EGLL-LOWI".gcmap # => Returns an image map URL for the route EGLL-LOWI
|
41
|
+
|
42
|
+
# It's not case sensitive:
|
43
|
+
"egll-lowi".gcmap # => Returns an image map URL for the route EGLL-LOWI
|
44
|
+
```
|
45
|
+
|
46
|
+
The resulting image size and look can be customized by passing an optional hash of arguments to the
|
47
|
+
`.gcmap` method. Customizable attributes include *width, height* and *terrain* (toggle satelite terrain overlay).
|
48
|
+
These options can be combined in any way or omitted entirely. Examples:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
# Passing width only (default is 720px):
|
52
|
+
route = "egll-lowi"
|
53
|
+
route.gcmap(:width => "600") # => Returns an image map URL with width set to 600px
|
54
|
+
|
55
|
+
# Passing height only (default is 360px):
|
56
|
+
route = "egll-lowi"
|
57
|
+
route.gcmap(:height => 400) # => Returns an image map URL with height set to 400px
|
58
|
+
|
59
|
+
# Passing width and height:
|
60
|
+
"egll-lowi".gcmap(:width => "800", :height => "400") # => Returns an image map URL with width 800px and height 400px
|
61
|
+
|
62
|
+
# Enabling terrain overlay:
|
63
|
+
route = "egll-lowi"
|
64
|
+
route.gcmap(:terrain => true) # => Returns an image map URL with terrain overlay enabled
|
65
|
+
|
66
|
+
# Setting width, height and enabling terrain overlay:
|
67
|
+
"egll-lowi".gcmap(:width => 800, :height => 400, :terrain => true) # => Returns an image map URL with set width, height and terrain
|
68
|
+
```
|
69
|
+
|
70
|
+
Finally, here's an example of how to use the gem in a Rails application:
|
71
|
+
|
72
|
+
*In your controller:*
|
73
|
+
```ruby
|
74
|
+
@route = "egll-lowi"
|
75
|
+
```
|
76
|
+
|
77
|
+
*In your view:*
|
78
|
+
```erb
|
79
|
+
<%= image_tag @route.gcmap(:width => "600") %>
|
80
|
+
```
|
81
|
+
|
82
|
+
#### Notes:
|
83
|
+
|
84
|
+
* the `route` string can be constructed from either ICAO or IATA airport codes; both types are recognized
|
85
|
+
* the `route` string is **not case sensitive**, so for example `lgav-lqsa` will be recognized as well
|
86
|
+
* layover routes that chain multiple airports (more than 2) are also supported
|
87
|
+
* default image parameters are: width 720px, width: 360px, terrain not shown
|
88
|
+
* when passing the `width` and `height` hash options the values can be put in quotes or not, either way works
|
89
|
+
|
90
|
+
## Contributing
|
91
|
+
|
92
|
+
1. Fork it
|
93
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
94
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
95
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
96
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/gcmapper.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/gcmapper/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Svilen Vassilev"]
|
6
|
+
gem.email = ["svilen@rubystudio.net"]
|
7
|
+
gem.description = %q{Easily generate Great Circle maps between 2 or more airports. The gem provides an API for constructing the image URLs, the maps themselves are pulled from gcmap.com.}
|
8
|
+
gem.summary = %q{A Ruby gem for easy generation of Great Circle Map images}
|
9
|
+
gem.homepage = "https://github.com/tarakanbg/gcmapper"
|
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 = "gcmapper"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Gcmapper::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency "rspec"
|
19
|
+
gem.add_development_dependency "rake"
|
20
|
+
end
|
data/lib/gcmapper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "gcmapper/version"
|
2
|
+
|
3
|
+
class String
|
4
|
+
def gcmap(args={})
|
5
|
+
Gcmapper.gcmap(self, args)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module Gcmapper
|
10
|
+
def self.gcmap(route, args)
|
11
|
+
args[:terrain].nil? || args[:terrain] == false ? tr="wls" : tr="bm"
|
12
|
+
args[:width].nil? ? width="720" : width=args[:width]
|
13
|
+
args[:height].nil? ? height="360" : height=args[:height]
|
14
|
+
|
15
|
+
url = "http://www.gcmap.com/map?P=#{route}%0d%0a&MS=#{tr}&MR=120&MX=#{width}x#{height}&PM=b:disc7%2b%22%25i%25+%28N%22"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe String do
|
4
|
+
|
5
|
+
describe "route" do
|
6
|
+
it "is a string" do
|
7
|
+
input = "egll-lbsf"
|
8
|
+
input.class.should eq(String)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe ".gcmap" do
|
13
|
+
|
14
|
+
it "should return a valid full url" do
|
15
|
+
route = "egll-lbsf"
|
16
|
+
route.gcmap[0..6].should eq("http://")
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should integrate the route correctly in the url" do
|
20
|
+
route = "egll-lowi"
|
21
|
+
route.gcmap.should eq("http://www.gcmap.com/map?P=egll-lowi%0d%0a&MS=wls&MR=120&MX=720x360&PM=b:disc7%2b%22%25i%25+%28N%22")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should interpret default width" do
|
25
|
+
route = "egll-lowi"
|
26
|
+
route.gcmap.should eq("http://www.gcmap.com/map?P=egll-lowi%0d%0a&MS=wls&MR=120&MX=720x360&PM=b:disc7%2b%22%25i%25+%28N%22")
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should interpret default height" do
|
30
|
+
route = "egll-lowi"
|
31
|
+
route.gcmap.should eq("http://www.gcmap.com/map?P=egll-lowi%0d%0a&MS=wls&MR=120&MX=720x360&PM=b:disc7%2b%22%25i%25+%28N%22")
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should be applicable directly to a string" do
|
35
|
+
"egll-lowi".gcmap.should eq("http://www.gcmap.com/map?P=egll-lowi%0d%0a&MS=wls&MR=120&MX=720x360&PM=b:disc7%2b%22%25i%25+%28N%22")
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should interpret non-default width" do
|
39
|
+
route = "egll-lowi"
|
40
|
+
route.gcmap(:width=>"600").should eq("http://www.gcmap.com/map?P=egll-lowi%0d%0a&MS=wls&MR=120&MX=600x360&PM=b:disc7%2b%22%25i%25+%28N%22")
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should interpret simplified non-default width" do
|
44
|
+
route = "egll-lowi"
|
45
|
+
route.gcmap(:width=>600).should eq("http://www.gcmap.com/map?P=egll-lowi%0d%0a&MS=wls&MR=120&MX=600x360&PM=b:disc7%2b%22%25i%25+%28N%22")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should interpret non-default height" do
|
49
|
+
route = "egll-lowi"
|
50
|
+
route.gcmap(:height=>"600").should eq("http://www.gcmap.com/map?P=egll-lowi%0d%0a&MS=wls&MR=120&MX=720x600&PM=b:disc7%2b%22%25i%25+%28N%22")
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should interpret simplified non-default height" do
|
54
|
+
route = "egll-lowi"
|
55
|
+
route.gcmap(:height=>600).should eq("http://www.gcmap.com/map?P=egll-lowi%0d%0a&MS=wls&MR=120&MX=720x600&PM=b:disc7%2b%22%25i%25+%28N%22")
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should interpret non-default width and height" do
|
59
|
+
route = "egll-lowi"
|
60
|
+
route.gcmap(:width=>"800", :height=>"400").should eq("http://www.gcmap.com/map?P=egll-lowi%0d%0a&MS=wls&MR=120&MX=800x400&PM=b:disc7%2b%22%25i%25+%28N%22")
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should interpret non-default simplified width and height" do
|
64
|
+
route = "egll-lowi"
|
65
|
+
route.gcmap(:width => 800, :height => 400).should eq("http://www.gcmap.com/map?P=egll-lowi%0d%0a&MS=wls&MR=120&MX=800x400&PM=b:disc7%2b%22%25i%25+%28N%22")
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should support layover routes" do
|
69
|
+
route = "egll-lowi-lqsa"
|
70
|
+
route.gcmap.should eq("http://www.gcmap.com/map?P=egll-lowi-lqsa%0d%0a&MS=wls&MR=120&MX=720x360&PM=b:disc7%2b%22%25i%25+%28N%22")
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should display terrain if needed" do
|
74
|
+
route = "egll-lowi"
|
75
|
+
route.gcmap(:terrain=>true).should eq("http://www.gcmap.com/map?P=egll-lowi%0d%0a&MS=bm&MR=120&MX=720x360&PM=b:disc7%2b%22%25i%25+%28N%22")
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should accept false option for terrain" do
|
79
|
+
route = "egll-lowi"
|
80
|
+
route.gcmap(:terrain=>false).should eq("http://www.gcmap.com/map?P=egll-lowi%0d%0a&MS=wls&MR=120&MX=720x360&PM=b:disc7%2b%22%25i%25+%28N%22")
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should allow random combination of arguments" do
|
84
|
+
route = "egll-lowi"
|
85
|
+
route.gcmap(:width=>800, :height=>400, :terrain=>true).should eq("http://www.gcmap.com/map?P=egll-lowi%0d%0a&MS=bm&MR=120&MX=800x400&PM=b:disc7%2b%22%25i%25+%28N%22")
|
86
|
+
route.gcmap(:width=>800, :terrain => true).should eq("http://www.gcmap.com/map?P=egll-lowi%0d%0a&MS=bm&MR=120&MX=800x360&PM=b:disc7%2b%22%25i%25+%28N%22")
|
87
|
+
route.gcmap(:height=>800, :terrain=>true).should eq("http://www.gcmap.com/map?P=egll-lowi%0d%0a&MS=bm&MR=120&MX=720x800&PM=b:disc7%2b%22%25i%25+%28N%22")
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'gcmapper'
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gcmapper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Svilen Vassilev
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-01 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: rake
|
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: Easily generate Great Circle maps between 2 or more airports. The gem
|
47
|
+
provides an API for constructing the image URLs, the maps themselves are pulled
|
48
|
+
from gcmap.com.
|
49
|
+
email:
|
50
|
+
- svilen@rubystudio.net
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- .gitignore
|
56
|
+
- .travis.yml
|
57
|
+
- Gemfile
|
58
|
+
- LICENSE
|
59
|
+
- README.md
|
60
|
+
- Rakefile
|
61
|
+
- gcmapper.gemspec
|
62
|
+
- lib/gcmapper.rb
|
63
|
+
- lib/gcmapper/version.rb
|
64
|
+
- spec/gcmapper_spec.rb
|
65
|
+
- spec/spec_helper.rb
|
66
|
+
homepage: https://github.com/tarakanbg/gcmapper
|
67
|
+
licenses: []
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.8.24
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: A Ruby gem for easy generation of Great Circle Map images
|
90
|
+
test_files:
|
91
|
+
- spec/gcmapper_spec.rb
|
92
|
+
- spec/spec_helper.rb
|