airports 1.0.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +56 -0
- data/.rubocop.yml +5 -0
- data/CHANGELOG.md +8 -0
- data/README.md +11 -1
- data/Rakefile +25 -25
- data/airports.gemspec +20 -29
- data/lib/airports.rb +22 -7
- data/lib/airports/version.rb +1 -1
- metadata +27 -35
- data/.travis.yml +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 001bb2bb68b337b4cd6a84bf91a460e3e00042df2b27acffde368d233b0f155b
|
4
|
+
data.tar.gz: 94d9b31f843346e005daa60df0b24468af5bcfb80a000017419b38a204414ec4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5dd63de8956bff030f825dfddd281d69a0ae7acd30897e8bb3173e17700e5ce470b1c7e4d1767f31fd333b7f3e255b875320839239459a40c30a058a3ddd8f59
|
7
|
+
data.tar.gz: db3a13c87145a9b9534f8d68bfffd057c7ecf804ae6ba79b569b5675125c62c7815361e4bb4af96a391ffa41744d763c725d81298d482b4fe0426f7781ebb31b
|
@@ -0,0 +1,56 @@
|
|
1
|
+
version: 2
|
2
|
+
|
3
|
+
references:
|
4
|
+
steps: &steps
|
5
|
+
- checkout
|
6
|
+
|
7
|
+
- type: cache-restore
|
8
|
+
key: airports-bundler-{{ checksum "airports.gemspec" }}
|
9
|
+
|
10
|
+
- run: gem install bundler
|
11
|
+
|
12
|
+
- run: bundle install --path vendor/bundle
|
13
|
+
|
14
|
+
- type: cache-save
|
15
|
+
key: airports-bundler-{{ checksum "airports.gemspec" }}
|
16
|
+
paths:
|
17
|
+
- vendor/bundle
|
18
|
+
|
19
|
+
- type: shell
|
20
|
+
command: |
|
21
|
+
bundle exec rspec --profile 10 \
|
22
|
+
--format RspecJunitFormatter \
|
23
|
+
--out /tmp/test-results/rspec.xml \
|
24
|
+
--format progress \
|
25
|
+
spec
|
26
|
+
|
27
|
+
- type: store_test_results
|
28
|
+
path: /tmp/test-results
|
29
|
+
|
30
|
+
- run: bundle exec rubocop
|
31
|
+
jobs:
|
32
|
+
build-ruby22:
|
33
|
+
docker:
|
34
|
+
- image: ruby:2.2
|
35
|
+
steps: *steps
|
36
|
+
build-ruby23:
|
37
|
+
docker:
|
38
|
+
- image: ruby:2.3
|
39
|
+
steps: *steps
|
40
|
+
build-ruby24:
|
41
|
+
docker:
|
42
|
+
- image: ruby:2.4
|
43
|
+
steps: *steps
|
44
|
+
build-ruby25:
|
45
|
+
docker:
|
46
|
+
- image: ruby:2.5
|
47
|
+
steps: *steps
|
48
|
+
|
49
|
+
workflows:
|
50
|
+
version: 2
|
51
|
+
tests:
|
52
|
+
jobs:
|
53
|
+
- build-ruby22
|
54
|
+
- build-ruby23
|
55
|
+
- build-ruby24
|
56
|
+
- build-ruby25
|
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# v1.2.0 (11 March 2018)
|
2
|
+
|
3
|
+
* Drop support for Ruby 2.2, which has reached end-of-life and no longer receives security updates (@timrogers)
|
4
|
+
* Enforce code style using Rubocop (@timrogers)
|
5
|
+
|
6
|
+
# v1.1.0 (11 March 2018)
|
7
|
+
|
8
|
+
* Add new `.find_by_icao_code` for finding airports by their ICAO code (@ryanburnett)
|
data/README.md
CHANGED
@@ -11,7 +11,7 @@ It's based on data from [OpenFlights](http://openflights.org), with a bit of mas
|
|
11
11
|
Install the gem by adding it to your Gemfile:
|
12
12
|
|
13
13
|
```ruby
|
14
|
-
gem 'airports', '~> 1.
|
14
|
+
gem 'airports', '~> 1.2.0'
|
15
15
|
```
|
16
16
|
|
17
17
|
You can then look up an airport by its IATA code (e.g. `LHR` for London Heathrow) using `Airports.find_by_iata_code`, which returns an object with a bunch of accessors like `name` and `city`:
|
@@ -21,6 +21,16 @@ Airports.find_by_iata_code("LHR")
|
|
21
21
|
=> #<Airports::Airport:0x007fd9a1bbd550 @name="Heathrow", @city="London", @country="United Kingdom", @iata="LHR", @icao="EGLL", @latitude="51.4775", @longitude="-0.461389", @altitude="83", @timezone="0", @dst="E">
|
22
22
|
```
|
23
23
|
|
24
|
+
You can also look up an airport by its ICAO code.
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
Airports.find_by_iata_code("KCRG")
|
28
|
+
=> #<Airports::Airport:0x00007fb548bea898 @altitude="41", @city="Jacksonville",
|
29
|
+
@country="United States", @dst="\\N", @iata="CRG", @icao="KCRG",
|
30
|
+
@latitude="30.3362998962", @longitude="-81.51439666750001", @name="Jacksonville
|
31
|
+
Executive at Craig Airport", @timezone="\\N">
|
32
|
+
```
|
33
|
+
|
24
34
|
A couple of other methods provide access to aggregate data.
|
25
35
|
|
26
36
|
You can call `Airports.iata_codes` for a list of valid IATA codes, perfect for Rails validations:
|
data/Rakefile
CHANGED
@@ -7,10 +7,11 @@ require "open-uri"
|
|
7
7
|
RSpec::Core::RakeTask.new(:spec)
|
8
8
|
|
9
9
|
task :update do
|
10
|
-
raw_data = open("https://raw.githubusercontent.com/jpatokal/openflights/master/data/
|
11
|
-
|
10
|
+
raw_data = open("https://raw.githubusercontent.com/jpatokal/openflights/master/data/" \
|
11
|
+
"airports.dat").read
|
12
|
+
cleaned_data = raw_data.gsub(/\\"/, '""')
|
12
13
|
|
13
|
-
|
14
|
+
cleaned_data = CSV.parse(cleaned_data).each_with_object({}) do |row, accumulator|
|
14
15
|
# Doha is missing its IATA code, for some reason 🙄
|
15
16
|
iata_code = row[5] == "OTBD" ? "DOH" : row[4]
|
16
17
|
|
@@ -24,28 +25,27 @@ task :update do
|
|
24
25
|
longitude: row[7],
|
25
26
|
altitude: row[8],
|
26
27
|
timezone: row[9],
|
27
|
-
dst: row[10]
|
28
|
+
dst: row[10],
|
28
29
|
}
|
29
|
-
end
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
File.open("data/airports.json", "w").puts JSON.generate(data)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Hyderabad (HYD) is missing, so add it in
|
33
|
+
cleaned_data["HYD"] = {
|
34
|
+
name: "Rajiv Gandhi International Airport",
|
35
|
+
city: "Hyderabad",
|
36
|
+
country: "India",
|
37
|
+
iata: "HYD",
|
38
|
+
icao: "VOHS",
|
39
|
+
latitude: "17.2403",
|
40
|
+
longitude: "78.4294",
|
41
|
+
altitude: nil,
|
42
|
+
timezone: "N",
|
43
|
+
dst: "5.5",
|
44
|
+
}
|
45
|
+
|
46
|
+
cleaned_data = cleaned_data.reject { |code, _| code.nil? || code == "" }
|
47
|
+
|
48
|
+
File.open("data/airports.json", "w").puts JSON.generate(cleaned_data)
|
49
49
|
end
|
50
50
|
|
51
|
-
task :
|
51
|
+
task default: :spec
|
data/airports.gemspec
CHANGED
@@ -1,41 +1,32 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path(
|
1
|
+
|
2
|
+
lib = File.expand_path("lib", __dir__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
4
|
+
require "airports/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name
|
8
|
-
spec.version
|
9
|
-
spec.authors
|
10
|
-
spec.email
|
11
|
-
|
12
|
-
spec.summary = %q{Access data on airports from around the world}
|
13
|
-
spec.description = %q{Access data on airports from around the world}
|
14
|
-
spec.homepage = "https://github.com/timrogers/airports"
|
15
|
-
spec.license = "MIT"
|
7
|
+
spec.name = "airports"
|
8
|
+
spec.version = Airports::VERSION
|
9
|
+
spec.authors = ["Tim Rogers"]
|
10
|
+
spec.email = ["me@timrogers.co.uk"]
|
16
11
|
|
17
|
-
spec.
|
12
|
+
spec.summary = "Access data on airports from around the world"
|
13
|
+
spec.description = "Access data on airports from around the world"
|
14
|
+
spec.homepage = "https://github.com/timrogers/airports"
|
15
|
+
spec.license = "MIT"
|
18
16
|
|
19
|
-
|
20
|
-
|
21
|
-
Dir.chdir(submodule_path) do
|
22
|
-
submodule_relative_path = submodule_path.sub gem_dir, ""
|
23
|
-
# issue git ls-files in submodule's directory and
|
24
|
-
# prepend the submodule path to create absolute file paths
|
25
|
-
`git ls-files`.split($\).each do |filename|
|
26
|
-
spec.files << "#{submodule_relative_path}/#{filename}"
|
27
|
-
end
|
28
|
-
end
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
29
19
|
end
|
30
20
|
|
31
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
32
22
|
spec.require_paths = ["lib"]
|
33
23
|
|
34
|
-
spec.required_ruby_version =
|
24
|
+
spec.required_ruby_version = ">= 2.2"
|
35
25
|
|
36
|
-
spec.add_development_dependency "
|
37
|
-
spec.add_development_dependency "
|
38
|
-
spec.add_development_dependency "
|
39
|
-
spec.add_development_dependency "rspec
|
40
|
-
spec.add_development_dependency "
|
26
|
+
spec.add_development_dependency "gc_ruboconfig", "~> 2.3.4"
|
27
|
+
spec.add_development_dependency "pry", "~> 0.10.3"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.3.0"
|
30
|
+
spec.add_development_dependency "rspec-its", "~> 1.2.0"
|
31
|
+
spec.add_development_dependency "rspec_junit_formatter", "~> 0.3.0"
|
41
32
|
end
|
data/lib/airports.rb
CHANGED
@@ -1,14 +1,29 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "json"
|
2
|
+
require "airports/version"
|
3
|
+
require "airports/airport"
|
4
4
|
|
5
5
|
module Airports
|
6
6
|
def self.find_by_iata_code(iata_code)
|
7
7
|
return unless iata_code.length == 3
|
8
|
-
|
8
|
+
airport_data = parsed_data.fetch(iata_code, nil)
|
9
|
+
|
10
|
+
return unless airport_data
|
11
|
+
|
12
|
+
Airport.
|
13
|
+
new(airport_data.each_with_object({}) { |(k, v), h| h[k.to_sym] = v })
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.find_by_icao_code(icao_code)
|
17
|
+
return unless icao_code.length == 4
|
18
|
+
|
19
|
+
airport_data = parsed_data.values.find do |data|
|
20
|
+
data["icao"] == icao_code
|
21
|
+
end
|
22
|
+
|
23
|
+
return unless airport_data
|
9
24
|
|
10
25
|
Airport.
|
11
|
-
new(airport_data.each_with_object({}) { |(k,v), h| h[k.to_sym] = v })
|
26
|
+
new(airport_data.each_with_object({}) { |(k, v), h| h[k.to_sym] = v })
|
12
27
|
end
|
13
28
|
|
14
29
|
def self.iata_codes
|
@@ -18,7 +33,7 @@ module Airports
|
|
18
33
|
def self.all
|
19
34
|
@all ||= parsed_data.map do |_iata_code, airport_data|
|
20
35
|
Airport.
|
21
|
-
new(airport_data.each_with_object({}) { |(k,v), h| h[k.to_sym] = v })
|
36
|
+
new(airport_data.each_with_object({}) { |(k, v), h| h[k.to_sym] = v })
|
22
37
|
end
|
23
38
|
end
|
24
39
|
|
@@ -32,7 +47,7 @@ module Airports
|
|
32
47
|
private_class_method :data
|
33
48
|
|
34
49
|
def self.data_path
|
35
|
-
File.expand_path("
|
50
|
+
File.expand_path("../data/airports.json", __dir__)
|
36
51
|
end
|
37
52
|
private_class_method :data_path
|
38
53
|
end
|
data/lib/airports/version.rb
CHANGED
metadata
CHANGED
@@ -1,47 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: airports
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Rogers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: gc_ruboconfig
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.3.4
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.3.4
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: pry
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
34
|
-
- - ">="
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: '10.0'
|
33
|
+
version: 0.10.3
|
37
34
|
type: :development
|
38
35
|
prerelease: false
|
39
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.10.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
40
44
|
requirements:
|
41
45
|
- - "~>"
|
42
46
|
- !ruby/object:Gem::Version
|
43
47
|
version: '10.0'
|
44
|
-
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
45
53
|
- !ruby/object:Gem::Version
|
46
54
|
version: '10.0'
|
47
55
|
- !ruby/object:Gem::Dependency
|
@@ -51,9 +59,6 @@ dependencies:
|
|
51
59
|
- - "~>"
|
52
60
|
- !ruby/object:Gem::Version
|
53
61
|
version: 3.3.0
|
54
|
-
- - ">="
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: 3.3.0
|
57
62
|
type: :development
|
58
63
|
prerelease: false
|
59
64
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -61,9 +66,6 @@ dependencies:
|
|
61
66
|
- - "~>"
|
62
67
|
- !ruby/object:Gem::Version
|
63
68
|
version: 3.3.0
|
64
|
-
- - ">="
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version: 3.3.0
|
67
69
|
- !ruby/object:Gem::Dependency
|
68
70
|
name: rspec-its
|
69
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -71,9 +73,6 @@ dependencies:
|
|
71
73
|
- - "~>"
|
72
74
|
- !ruby/object:Gem::Version
|
73
75
|
version: 1.2.0
|
74
|
-
- - ">="
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: 1.2.0
|
77
76
|
type: :development
|
78
77
|
prerelease: false
|
79
78
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -81,29 +80,20 @@ dependencies:
|
|
81
80
|
- - "~>"
|
82
81
|
- !ruby/object:Gem::Version
|
83
82
|
version: 1.2.0
|
84
|
-
- - ">="
|
85
|
-
- !ruby/object:Gem::Version
|
86
|
-
version: 1.2.0
|
87
83
|
- !ruby/object:Gem::Dependency
|
88
|
-
name:
|
84
|
+
name: rspec_junit_formatter
|
89
85
|
requirement: !ruby/object:Gem::Requirement
|
90
86
|
requirements:
|
91
87
|
- - "~>"
|
92
88
|
- !ruby/object:Gem::Version
|
93
|
-
version: 0.
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: 0.10.3
|
89
|
+
version: 0.3.0
|
97
90
|
type: :development
|
98
91
|
prerelease: false
|
99
92
|
version_requirements: !ruby/object:Gem::Requirement
|
100
93
|
requirements:
|
101
94
|
- - "~>"
|
102
95
|
- !ruby/object:Gem::Version
|
103
|
-
version: 0.
|
104
|
-
- - ">="
|
105
|
-
- !ruby/object:Gem::Version
|
106
|
-
version: 0.10.3
|
96
|
+
version: 0.3.0
|
107
97
|
description: Access data on airports from around the world
|
108
98
|
email:
|
109
99
|
- me@timrogers.co.uk
|
@@ -111,9 +101,11 @@ executables: []
|
|
111
101
|
extensions: []
|
112
102
|
extra_rdoc_files: []
|
113
103
|
files:
|
104
|
+
- ".circleci/config.yml"
|
114
105
|
- ".gitignore"
|
115
106
|
- ".rspec"
|
116
|
-
- ".
|
107
|
+
- ".rubocop.yml"
|
108
|
+
- CHANGELOG.md
|
117
109
|
- CODE_OF_CONDUCT.md
|
118
110
|
- Gemfile
|
119
111
|
- LICENSE.txt
|
@@ -138,7 +130,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
138
130
|
requirements:
|
139
131
|
- - ">="
|
140
132
|
- !ruby/object:Gem::Version
|
141
|
-
version: '2.
|
133
|
+
version: '2.2'
|
142
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
135
|
requirements:
|
144
136
|
- - ">="
|
@@ -146,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
138
|
version: '0'
|
147
139
|
requirements: []
|
148
140
|
rubyforge_project:
|
149
|
-
rubygems_version: 2.
|
141
|
+
rubygems_version: 2.7.4
|
150
142
|
signing_key:
|
151
143
|
specification_version: 4
|
152
144
|
summary: Access data on airports from around the world
|