locode 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ module Locode
2
+ MAJOR = 0
3
+ MINOR = 1
4
+ PATCH = 0
5
+ VERSION = "#{MAJOR}.#{MINOR}.#{PATCH}"
6
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'locode/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'locode'
8
+ spec.version = Locode::VERSION
9
+ spec.authors = ['Patrick Detlefsen']
10
+ spec.email = ['patrick.detlefsen@gmail.com']
11
+ spec.description = %q{The Locode gem gives you the ability to lookup UN/LOCODE codes.}
12
+ spec.summary = %q{The Locode gem gives you the ability to lookup UN/LOCODE codes.}
13
+ spec.homepage = 'https://github.com/patrickdet/locode'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'multi_json', '~> 1.0'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.3'
24
+ spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'pry'
26
+ end
@@ -0,0 +1,84 @@
1
+ require_relative '../test_helper'
2
+
3
+ describe Locode::Location do
4
+ describe '.new' do
5
+ it 'must return a valid Location for valid parameters' do
6
+ location_attributes = {
7
+ country_code: 'US',
8
+ city_code: 'NYC',
9
+ full_name: 'New York',
10
+ full_name_without_diacritics: 'New York',
11
+ subdivision: 'NY',
12
+ function_classifier: '12345---',
13
+ status: 'AI',
14
+ date: '0401',
15
+ iata_code: '',
16
+ coordinates: '4042N 07400W'
17
+ }
18
+ location = Locode::Location.new(location_attributes)
19
+
20
+ assert location.valid?
21
+ end
22
+
23
+ it 'returns an invalid Location object for invalid parameters' do
24
+ location_attributes = {
25
+ foo: 'bar'
26
+ }
27
+ location = Locode::Location.new(location_attributes)
28
+
29
+ refute location.valid?
30
+ end
31
+ end
32
+
33
+ describe 'to_json' do
34
+ let(:location) { Locode::Location.new({
35
+ country_code: 'US',
36
+ city_code: 'NYC',
37
+ full_name: 'New York',
38
+ full_name_without_diacritics: 'New York',
39
+ subdivision: 'NY',
40
+ function_classifier: '12345---',
41
+ status: 'AI',
42
+ date: '0401',
43
+ iata_code: '',
44
+ coordinates: '4042N 07400W'
45
+ }) }
46
+
47
+ it 'should return a json output' do
48
+ json = MultiJson.load(location.to_json)
49
+ json['country_code'].must_equal location.country_code
50
+ json['city_code'].must_equal location.city_code
51
+ json['full_name'].must_equal location.full_name
52
+ json['full_name_without_diacritics'].must_equal location.full_name_without_diacritics
53
+ json['subdivision'].must_equal location.subdivision
54
+ json['function_classifier'].must_equal location.function_classifier
55
+ json['status'].must_equal location.status.to_s
56
+ json['date'].must_equal location.date
57
+ json['iata_code'].must_equal location.iata_code
58
+ json['coordinates'].must_equal location.coordinates
59
+ end
60
+ end
61
+
62
+ describe 'to_h' do
63
+ let(:attributes) { {
64
+ country_code: 'US',
65
+ city_code: 'NYC',
66
+ full_name: 'New York',
67
+ full_name_without_diacritics: 'New York',
68
+ subdivision: 'NY',
69
+ function_classifier: '12345---',
70
+ status: 'AI',
71
+ date: '0401',
72
+ iata_code: '',
73
+ coordinates: '4042N 07400W'
74
+ } }
75
+ let(:location) { Locode::Location.new(attributes) }
76
+
77
+ it 'should return a hash' do
78
+ hash = location.to_h
79
+ hash.must_be_instance_of Hash
80
+ hash[:subdivision].must_equal location.subdivision
81
+ hash[:coordinates].must_equal location.coordinates
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,7 @@
1
+ require_relative '../test_helper'
2
+
3
+ describe Locode do
4
+ it "must have a defined version" do
5
+ Locode::VERSION.wont_be_nil
6
+ end
7
+ end
@@ -0,0 +1,102 @@
1
+ require_relative 'test_helper'
2
+
3
+ describe Locode do
4
+ describe '.find_by_locode' do
5
+ it 'should return the correct location' do
6
+ locode = 'DE HAM'
7
+ location = Locode.find_by_locode(locode).first
8
+
9
+ location.locode.must_equal locode
10
+ end
11
+ end
12
+
13
+ describe '.find_by_name' do
14
+ it 'should find the location for a given name' do
15
+ name = 'Hamburg'
16
+ location = Locode.find_by_name(name).first
17
+
18
+ location.full_name.must_equal name
19
+ end
20
+ end
21
+
22
+ describe 'find locations by country for function' do
23
+
24
+ describe 'invalid calls' do
25
+ it 'returns an empty array when country code is empty' do
26
+ Locode.find_by_country_and_function(nil, 1).must_be_empty
27
+ end
28
+
29
+ it 'returns an empty array when country code is not a string' do
30
+ Locode.find_by_country_and_function(12, 1).must_be_empty
31
+ end
32
+
33
+ it 'returns an empty array when country code is not 2 chars long' do
34
+ Locode.find_by_country_and_function('ABC', 1).must_be_empty
35
+ Locode.find_by_country_and_function('A', 1).must_be_empty
36
+ end
37
+
38
+ it 'returns an empty array when country code is not in upper case' do
39
+ Locode.find_by_country_and_function('aa', 1).must_be_empty
40
+ Locode.find_by_country_and_function('a', 1).must_be_empty
41
+ end
42
+
43
+ it 'returns an empty array when function is not a possible function' do
44
+ Locode.find_by_country_and_function('AB', 9).must_be_empty
45
+ Locode.find_by_country_and_function('AB', 0).must_be_empty
46
+ Locode.find_by_country_and_function('AB', nil).must_be_empty
47
+ Locode.find_by_country_and_function('AB', ':C').must_be_empty
48
+ Locode.find_by_country_and_function('AB', ':b').must_be_empty
49
+ end
50
+ end
51
+
52
+ describe 'valid calls' do
53
+ let(:seaport) { Locode::Location.new country_code: 'BE', full_name: 'Antwerp', function_classifier: [1] }
54
+ let(:airport) { Locode::Location.new country_code: 'BE', full_name: 'Brussels', function_classifier: [4] }
55
+ let(:railstation) { Locode::Location.new country_code: 'NL', full_name: 'Venlo', function_classifier: [2] }
56
+ let(:locations) { [] }
57
+
58
+ before(:each) do
59
+ Locode.const_set :ALL_LOCATIONS, locations
60
+ end
61
+
62
+ describe 'without limit' do
63
+ before(:each) do
64
+ locations << seaport << airport << railstation
65
+ end
66
+
67
+ it 'excepts :B as a valid function' do
68
+ Locode.find_by_country_and_function('AB', ':B').must_be_empty
69
+ end
70
+
71
+ it 'finds all locations for Belgium as seaport' do
72
+ locations = Locode.find_by_country_and_function('BE', 1)
73
+ locations.count.must_equal 1
74
+ locations.must_include seaport
75
+ locations.wont_include airport
76
+ locations.wont_include railstation
77
+ end
78
+
79
+ it 'finds all railstations in the Netherlands' do
80
+ locations = Locode.find_by_country_and_function('NL', 2)
81
+ locations.count.must_equal 1
82
+ locations.must_include railstation
83
+ locations.wont_include airport
84
+ locations.wont_include seaport
85
+ end
86
+ end
87
+
88
+ describe 'with limit' do
89
+ before(:each) do
90
+ locations << railstation << railstation << railstation
91
+ end
92
+
93
+ [1, 2].each do |limit|
94
+ it "returns array with the #{limit} location" do
95
+ locations = Locode.find_by_country_and_function('NL', 2, limit)
96
+ locations.count.must_equal limit
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,4 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/pride'
3
+ require 'pry'
4
+ require File.expand_path('../../lib/locode.rb', __FILE__)
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: locode
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Patrick Detlefsen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: multi_json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: The Locode gem gives you the ability to lookup UN/LOCODE codes.
70
+ email:
71
+ - patrick.detlefsen@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .travis.yml
78
+ - CONTRIBUTERS
79
+ - Gemfile
80
+ - LICENSE
81
+ - README.md
82
+ - Rakefile
83
+ - data/README.md
84
+ - data/locode_data_update.rb
85
+ - data/yaml/dump.yml
86
+ - lib/locode.rb
87
+ - lib/locode/location.rb
88
+ - lib/locode/version.rb
89
+ - locode.gemspec
90
+ - test/lib/location_test.rb
91
+ - test/lib/version_test.rb
92
+ - test/locode_test.rb
93
+ - test/test_helper.rb
94
+ homepage: https://github.com/patrickdet/locode
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.0.3
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: The Locode gem gives you the ability to lookup UN/LOCODE codes.
118
+ test_files:
119
+ - test/lib/location_test.rb
120
+ - test/lib/version_test.rb
121
+ - test/locode_test.rb
122
+ - test/test_helper.rb