un_locode 0.0.2 → 0.0.3

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: f843ce7d89a6836d813645eef8e25604b5e668a7
4
- data.tar.gz: 9d4ef8ae89b500d2a5a6497a6b71beee39014100
3
+ metadata.gz: 7b06f8f05e17efdeda5e901a32f34d708f84ab9e
4
+ data.tar.gz: a700f46dc345bc712b7c088a7afb58e30bb32794
5
5
  SHA512:
6
- metadata.gz: 90090d9612bb9440bcf1d3c347edc025ac52dff7efb7497be3bccc9c420dde6e657a0d36a1f4119ed660c75fe79ebb957d1227b04e3e94caf15195837583329c
7
- data.tar.gz: 55c0660472fb6dd682a06feff090d466bd1ee460d16a9b1b1ec6adf0e00a37e5e64f8f0ef9fd01d082721a28174457a3e1379947f4843fe2f2fe0e46bd8712ee
6
+ metadata.gz: f665092d6646483001e569b5bb699ccdd4b61d38e0fdaa68c9204cd91731c499ccf43ed0719ba445e8cd9d01c5e1bbea01710dfee0e71f55927d138ab7de5213
7
+ data.tar.gz: 4c8d8faf20e6534a93032e287b34a782b347fc439f9d76ddfa4604ae4dc1168c0270c27ae1723b7926239a15045398b03c00812eb43022a12fbd4b0f8221816d
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Locode
2
2
 
3
+ [![Build Status](https://travis-ci.org/kabisaict/un_locode.png)](https://travis-ci.org/kabisaict/un_locode)
4
+ [![Gem Version](https://badge.fury.io/rb/un_locode.png)](http://badge.fury.io/rb/un_locode)
5
+
3
6
  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
7
 
5
8
  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.**
@@ -37,6 +40,11 @@ Like above you can limit the query result.
37
40
  UnLocode::Locode.find_by_name_and_function('US', :port)
38
41
  #=> ActiveRecord::Relation [#<UnLocode::Locode name: "Abu Musa", ... >, #<UnLocode::Locode name: "Mussafah",...>, ...
39
42
 
43
+ - **find_by_locode**: Return Locode object based on locode string. String needs to be in format `NL VEN`. You can access country code using `#country.code`.
44
+
45
+ UnLocode::Locode.find_by_locode('NL VEN')
46
+ => #<UnLocode::Locode id: 65419, country_id: 165, city_code: "VEN", name: "Venlo">
47
+
40
48
  - **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
49
 
42
50
  UnLocode::Locode.find_by_function(:port, 2)
@@ -54,11 +62,11 @@ Like above you can limit the query result.
54
62
 
55
63
  You can find more explaination of the functions over [here](http://www.unece.org/fileadmin/DAM/cefact/locode/Service/LocodeColumn.htm)
56
64
 
57
- ## TODO
65
+ ## TODO's
58
66
  - add locode method to location (also export with as_json)
59
67
  - add tests for limit's
60
- - add find_by_locode method
61
68
  - use connectionpool for connection management
69
+ - make logging configurable option
62
70
 
63
71
  ## Contributing
64
72
 
@@ -66,4 +74,4 @@ Like above you can limit the query result.
66
74
  2. Create your feature branch (`git checkout -b my-new-feature`)
67
75
  3. Commit your changes (`git commit -am 'Add some feature'`)
68
76
  4. Push to the branch (`git push origin my-new-feature`)
69
- 5. Create new Pull Request
77
+ 5. Create new Pull Request
@@ -28,8 +28,14 @@ module UnLocode
28
28
  find_by_fuzzy_name(name).find_by_function(function, limit)
29
29
  end
30
30
 
31
+ def self.find_by_locode(locode)
32
+ locode = locode.split(' ')
33
+ includes(:country).where(city_code: locode.last)
34
+ .where(countries: { code: locode.first }).first
35
+ end
36
+
31
37
  def as_json options = {}
32
38
  super(options.merge!(except: [:id, :country_id])).merge('country' => country.as_json)
33
39
  end
34
40
  end
35
- end
41
+ end
@@ -1,3 +1,3 @@
1
1
  module UnLocode
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -89,6 +89,19 @@ describe UnLocode::Locode do
89
89
  end
90
90
  end
91
91
  end
92
+
93
+ describe 'retrieving country by locode' do
94
+ let!(:country) { UnLocode::Country.create name: 'NETHERLANDS', code: 'NL' }
95
+ let!(:location) { UnLocode::Locode.create name: 'Venlo', city_code: 'VEN', country: country }
96
+
97
+ context 'with supported functions' do
98
+ subject { UnLocode::Locode.find_by_locode(search_term) }
99
+ let(:search_term) { 'NL VEN' }
100
+
101
+ its(:name) { should eql('Venlo') }
102
+ its(:country) { should eql(country) }
103
+ end
104
+ end
92
105
  end
93
106
 
94
107
  describe 'as_json' do
data/un_locode.gemspec CHANGED
@@ -6,8 +6,8 @@ require 'un_locode/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'un_locode'
8
8
  spec.version = UnLocode::VERSION
9
- spec.authors = ['Michel de Graaf', 'Rui Salgado', 'Niels Stevens']
10
- spec.email = ['michel@kabisa.nl', 'rui.salgado@kabisa.nl', 'niels@kabisa.nl']
9
+ spec.authors = ['Michel de Graaf', 'Rui Salgado', 'Niels Stevens', 'Jean Mertz']
10
+ spec.email = ['michel@kabisa.nl', 'rui.salgado@kabisa.nl', 'niels@kabisa.nl', 'jean@kabisa.nl']
11
11
  spec.description = %q{The Locode gem gives you the ability to lookup UN/LOCODE codes.}
12
12
  spec.summary = %q{The Locode gem gives you the ability to lookup UN/LOCODE codes.}
13
13
  spec.homepage = 'https://github.com/kabisaict/un_locode'
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_development_dependency 'bundler', '~> 1.3.5'
21
+ spec.add_development_dependency 'bundler', '~> 1.5.1'
22
22
  spec.add_development_dependency 'rake', '~> 10.1.0'
23
23
  spec.add_development_dependency 'rspec', '~> 2.14.1'
24
24
  spec.add_development_dependency 'pry', '~> 0.9.12.3'
metadata CHANGED
@@ -1,16 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: un_locode
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michel de Graaf
8
8
  - Rui Salgado
9
9
  - Niels Stevens
10
+ - Jean Mertz
10
11
  autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
- date: 2013-11-29 00:00:00.000000000 Z
14
+ date: 2014-01-29 00:00:00.000000000 Z
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: bundler
@@ -18,14 +19,14 @@ dependencies:
18
19
  requirements:
19
20
  - - ~>
20
21
  - !ruby/object:Gem::Version
21
- version: 1.3.5
22
+ version: 1.5.1
22
23
  type: :development
23
24
  prerelease: false
24
25
  version_requirements: !ruby/object:Gem::Requirement
25
26
  requirements:
26
27
  - - ~>
27
28
  - !ruby/object:Gem::Version
28
- version: 1.3.5
29
+ version: 1.5.1
29
30
  - !ruby/object:Gem::Dependency
30
31
  name: rake
31
32
  requirement: !ruby/object:Gem::Requirement
@@ -115,6 +116,7 @@ email:
115
116
  - michel@kabisa.nl
116
117
  - rui.salgado@kabisa.nl
117
118
  - niels@kabisa.nl
119
+ - jean@kabisa.nl
118
120
  executables: []
119
121
  extensions: []
120
122
  extra_rdoc_files: []