un_locode 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3793656f2e8a019e5f31026caac9967ec35946e5
4
- data.tar.gz: 62959bd158236bde648d9a68a690adaf3d53ba20
3
+ metadata.gz: f843ce7d89a6836d813645eef8e25604b5e668a7
4
+ data.tar.gz: 9d4ef8ae89b500d2a5a6497a6b71beee39014100
5
5
  SHA512:
6
- metadata.gz: c21c0b8702f0d0e70846d08cdc91c55340510c4d70ecb4780b74a8671d2640e6fe73c8a472a08f39bc89e4246bdb571544ec8f75404eb76be1192426366323e1
7
- data.tar.gz: f6437cc441506e37f35987c02d7a4344b31adc4f9853b79a19d31bfedd5982341abe65771e8c6caa2b1d61058187333d2a06dfd49bf86635b73cded7f010b9c4
6
+ metadata.gz: 90090d9612bb9440bcf1d3c347edc025ac52dff7efb7497be3bccc9c420dde6e657a0d36a1f4119ed660c75fe79ebb957d1227b04e3e94caf15195837583329c
7
+ data.tar.gz: 55c0660472fb6dd682a06feff090d466bd1ee460d16a9b1b1ec6adf0e00a37e5e64f8f0ef9fd01d082721a28174457a3e1379947f4843fe2f2fe0e46bd8712ee
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+
6
+ script: rspec spec
data/README.md CHANGED
@@ -1,10 +1,12 @@
1
1
  # Locode
2
2
 
3
- The 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).
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
- UnLocode::Locode.find_by_fuzzy_name('Göte', 5)
30
- #=> [#<UnLocode::Locode city_code: "GOT", name: "Göteborg", ...
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
- UnLocode::Locode.find_by_name_and_function('US', :port)
37
- #=> [<UnLocode::Locode: city_code: "GOT", name: ">,>
38
- <UnLocode::Locode: 'US LAX'>, ... ]
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
 
@@ -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.find_by_name_and_function name, function, limit = 10
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
- find_by_fuzzy_name(name).where(function => true).limit(limit)
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 = {}
@@ -1,3 +1,3 @@
1
1
  module UnLocode
2
- VERSION = "0.0.1"
2
+ VERSION = '0.0.2'
3
3
  end
@@ -42,7 +42,7 @@ describe UnLocode::Locode do
42
42
 
43
43
  end
44
44
 
45
- context 'retrieving locodes by name and function' do
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.1
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-27 00:00:00.000000000 Z
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