un_locode 0.0.1 → 0.0.2
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 +4 -4
- data/.travis.yml +6 -0
- data/README.md +33 -10
- data/lib/un_locode/locode.rb +7 -3
- data/lib/un_locode/version.rb +1 -1
- data/spec/un_locode_spec.rb +30 -2
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f843ce7d89a6836d813645eef8e25604b5e668a7
|
|
4
|
+
data.tar.gz: 9d4ef8ae89b500d2a5a6497a6b71beee39014100
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 90090d9612bb9440bcf1d3c347edc025ac52dff7efb7497be3bccc9c420dde6e657a0d36a1f4119ed660c75fe79ebb957d1227b04e3e94caf15195837583329c
|
|
7
|
+
data.tar.gz: 55c0660472fb6dd682a06feff090d466bd1ee460d16a9b1b1ec6adf0e00a37e5e64f8f0ef9fd01d082721a28174457a3e1379947f4843fe2f2fe0e46bd8712ee
|
data/.travis.yml
ADDED
data/README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
# Locode
|
|
2
2
|
|
|
3
|
-
The
|
|
3
|
+
The un_locode gem gives you the ability to lookup UN/LOCODE codes. You can read more about the UN/LOCODE specifications here: [wiki](http://en.wikipedia.org/wiki/UN/LOCODE) and [UNECE](http://www.unece.org/fileadmin/DAM/cefact/locode/Service/LocodeColumn.htm).
|
|
4
4
|
|
|
5
5
|
All data used by this gem has been taken from the *UN Centre for Trade Facilitation and E-business* official website. **No guarantees for the accuracy or up-to-dateness are given.**
|
|
6
6
|
|
|
7
|
-
`http://www.unece.org/cefact/locode/welcome.html` and `http://www.unece.org/cefact/codesfortrade/codes_index.html`
|
|
7
|
+
`http://www.unece.org/cefact/locode/welcome.html` and `http://www.unece.org/cefact/codesfortrade/codes_index.html` and `http://www.unece.org/fileadmin/DAM/cefact/locode/Service/LocodeColumn.htm`
|
|
8
|
+
|
|
9
|
+
Unlike the [locode gem](https://github.com/patrickdet/locode) by [patrickdet](https://github.com/patrickdet) our implementation uses a local sqlite DB to search for locodes instead of loading all the locodes(~90000) into memory. Therefore our gem only uses a fraction of the memory needed by the [locode gem](https://github.com/patrickdet/locode).
|
|
8
10
|
|
|
9
11
|
## Installation
|
|
10
12
|
|
|
@@ -22,20 +24,41 @@ Or install it yourself as:
|
|
|
22
24
|
|
|
23
25
|
## Usage
|
|
24
26
|
|
|
25
|
-
Find locations whose name is like the supplied search string. The search is case insensitive and also tries to match
|
|
27
|
+
- **find_by_fuzzy_name**: Find locations whose name is like the supplied search string. The search is case insensitive and also tries to match
|
|
26
28
|
location name without diacritics (and also alternative names when available). By default the amount of locations
|
|
27
29
|
returned are 10 but you can override this value by passing a number as second argument.
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
UnLocode::Locode.find_by_fuzzy_name('Göte', 5)
|
|
32
|
+
#=> ActiveRecord::Relation [#<UnLocode::Locode city_code: "GOT", name: "Göteborg", ...
|
|
32
33
|
|
|
33
|
-
Same search mechanisms as above but filter by function. You can find a list of possible functions @ UnLocode::FUNCTIONS.
|
|
34
|
+
- **find_by_name_and_function**: Same search mechanisms as above but filter by function. You can find a list of possible functions @ UnLocode::FUNCTIONS.
|
|
34
35
|
Like above you can limit the query result.
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
UnLocode::Locode.find_by_name_and_function('US', :port)
|
|
38
|
+
#=> ActiveRecord::Relation [#<UnLocode::Locode name: "Abu Musa", ... >, #<UnLocode::Locode name: "Mussafah",...>, ...
|
|
39
|
+
|
|
40
|
+
- **find_by_function**: Find all locations for a certain function.You can find a list of possible functions @ UnLocode::FUNCTIONS. Like all find methods, the default limit is 10 but can be specified to your own needs.
|
|
41
|
+
|
|
42
|
+
UnLocode::Locode.find_by_function(:port, 2)
|
|
43
|
+
#=> <UnLocode::Locode name: "Abu al Bukhoosh", port: true, ...>, #<UnLocode::Locode name: "Abu Dhabi", port: true>]>
|
|
44
|
+
|
|
45
|
+
#### Available functions
|
|
46
|
+
- :port
|
|
47
|
+
- :rail_terminal
|
|
48
|
+
- :road_terminal
|
|
49
|
+
- :airport
|
|
50
|
+
- :postal_exchange_office
|
|
51
|
+
- :inland_clearance_depot
|
|
52
|
+
- :fixed_transport_functions
|
|
53
|
+
- :border_crossing_function
|
|
54
|
+
|
|
55
|
+
You can find more explaination of the functions over [here](http://www.unece.org/fileadmin/DAM/cefact/locode/Service/LocodeColumn.htm)
|
|
56
|
+
|
|
57
|
+
## TODO
|
|
58
|
+
- add locode method to location (also export with as_json)
|
|
59
|
+
- add tests for limit's
|
|
60
|
+
- add find_by_locode method
|
|
61
|
+
- use connectionpool for connection management
|
|
39
62
|
|
|
40
63
|
## Contributing
|
|
41
64
|
|
data/lib/un_locode/locode.rb
CHANGED
|
@@ -12,16 +12,20 @@ module UnLocode
|
|
|
12
12
|
belongs_to :country
|
|
13
13
|
|
|
14
14
|
def self.find_by_fuzzy_name name, limit = 10
|
|
15
|
-
where('name like ? or
|
|
15
|
+
includes(:country).where('name like ? or
|
|
16
16
|
name_wo_diacritics like ? or
|
|
17
17
|
alternative_name like ? or
|
|
18
18
|
alternative_name_wo_diacritics like ?',
|
|
19
19
|
"%#{name}%", "%#{name}%", "%#{name}%", "%#{name}%").limit(limit)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
def self.
|
|
22
|
+
def self.find_by_function function, limit = 10
|
|
23
23
|
raise "Unsupported Locode Function! Should be one of #{UnLocode::FUNCTIONS.join(' ')}." unless UnLocode::FUNCTIONS.include?(function)
|
|
24
|
-
|
|
24
|
+
includes(:country).where(function => true).limit(limit)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.find_by_name_and_function name, function, limit = 10
|
|
28
|
+
find_by_fuzzy_name(name).find_by_function(function, limit)
|
|
25
29
|
end
|
|
26
30
|
|
|
27
31
|
def as_json options = {}
|
data/lib/un_locode/version.rb
CHANGED
data/spec/un_locode_spec.rb
CHANGED
|
@@ -42,7 +42,7 @@ describe UnLocode::Locode do
|
|
|
42
42
|
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
describe 'retrieving locodes by name and function' do
|
|
46
46
|
let!(:port) { UnLocode::Locode.create(name: 'Eindhoven', port: true) }
|
|
47
47
|
let!(:rail_terminal) { UnLocode::Locode.create(name: 'Eindhoven', rail_terminal: true) }
|
|
48
48
|
|
|
@@ -60,6 +60,35 @@ describe UnLocode::Locode do
|
|
|
60
60
|
end
|
|
61
61
|
end
|
|
62
62
|
end
|
|
63
|
+
|
|
64
|
+
describe 'retrieves locodes for' do
|
|
65
|
+
let!(:port) { UnLocode::Locode.create(name: 'Eindhoven', port: true) }
|
|
66
|
+
let!(:airport) { UnLocode::Locode.create(name: 'Eindhoven', airport: true) }
|
|
67
|
+
|
|
68
|
+
subject { UnLocode::Locode.find_by_function(function) }
|
|
69
|
+
|
|
70
|
+
context 'ports function' do
|
|
71
|
+
let(:function) { :port }
|
|
72
|
+
|
|
73
|
+
its(:first) { should eql(port) }
|
|
74
|
+
its(:count) { should eql(1) }
|
|
75
|
+
it { should_not include airport }
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
context 'airports function' do
|
|
79
|
+
let(:function) { :airport }
|
|
80
|
+
|
|
81
|
+
its(:first) { should eql(airport) }
|
|
82
|
+
its(:count) { should eql(1) }
|
|
83
|
+
it { should_not include port }
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
context 'unsupported function' do
|
|
87
|
+
it 'raises an error' do
|
|
88
|
+
expect { UnLocode::Locode.find_by_function(:derp) }.to raise_error
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
63
92
|
end
|
|
64
93
|
|
|
65
94
|
describe 'as_json' do
|
|
@@ -73,4 +102,3 @@ describe UnLocode::Locode do
|
|
|
73
102
|
it { should_not have_key('id') }
|
|
74
103
|
end
|
|
75
104
|
end
|
|
76
|
-
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: un_locode
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Michel de Graaf
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2013-11-
|
|
13
|
+
date: 2013-11-29 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: bundler
|
|
@@ -123,6 +123,7 @@ files:
|
|
|
123
123
|
- .gitignore
|
|
124
124
|
- .rspec
|
|
125
125
|
- .ruby-version
|
|
126
|
+
- .travis.yml
|
|
126
127
|
- Gemfile
|
|
127
128
|
- LICENSE.txt
|
|
128
129
|
- README.md
|