un_locode 0.0.4 → 0.0.5

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: 6b2ad7a1efc457f1b2eb89fc3b3cb1299492e17f
4
- data.tar.gz: 4ed762adb6e2b0eab5b8b23fcd68c38f7d7bb44b
3
+ metadata.gz: 77e82eda82d1196c613e18cb50e64e6dc8decc29
4
+ data.tar.gz: f1342cfbdd1deba5f104214229804585e0bb4763
5
5
  SHA512:
6
- metadata.gz: 983e46fd27f67d4e596ead59d59f05d52b72376867f93f48323b4c871630cdaf2caf11f32e7622d6c58abb26f20f7e5a2c41737f086af91564672b12849bdaea
7
- data.tar.gz: 2a511ea2736af6f4b03a96fc5607d17f4fadaa2d29f0a5f315b501a0881b97a6c88fccfab4b41f46bef169d3bb6c3950df5131d53a6591d51125e5ad517baa1f
6
+ metadata.gz: b1bb35412af0bae937672e59a74ecb4776d2753873bcffb0865726a79eeaf26671afe38b3be1f3ad854f027b76fe9c3a633de709807e3cfc2c45fce96d851569
7
+ data.tar.gz: 33fa3890ec41ee225a694dcca692e6245206952f9a7ddac0df4482ebcd343e37e00b3e1c866ca148d2f879e87ff531f7e11e7565524b16f9a716e061026c3f57
data/.hound.yml ADDED
@@ -0,0 +1,2 @@
1
+ ruby:
2
+ config_file: .ruby-style.yml
data/.ruby-style.yml ADDED
@@ -0,0 +1,25 @@
1
+ Metrics/LineLength:
2
+ Description: Limit lines to 80 characters.
3
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#80-character-limits
4
+ Enabled: true
5
+ Max: 120
6
+ AllowURI: true
7
+ URISchemes:
8
+ - http
9
+ - https
10
+ Style/StringLiterals:
11
+ Description: Checks if uses of quotes match the configured preference.
12
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-string-literals
13
+ Enabled: true
14
+ EnforcedStyle: single_quotes
15
+ SupportedStyles:
16
+ - single_quotes
17
+ - double_quotes
18
+ Style/StringLiteralsInInterpolation:
19
+ Description: Checks if uses of quotes inside expressions in interpolated strings
20
+ match the configured preference.
21
+ Enabled: true
22
+ EnforcedStyle: single_quotes
23
+ SupportedStyles:
24
+ - single_quotes
25
+ - double_quotes
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Locode
2
2
 
3
- [![Build Status](https://travis-ci.org/kabisaict/un_locode.png)](https://travis-ci.org/kabisaict/un_locode)
3
+ [![Build Status](https://travis-ci.org/kabisa/un_locode.svg?branch=master)](https://travis-ci.org/kabisa/un_locode)
4
4
  [![Gem Version](https://badge.fury.io/rb/un_locode.png)](http://badge.fury.io/rb/un_locode)
5
5
 
6
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).
@@ -29,9 +29,8 @@ module UnLocode
29
29
  end
30
30
 
31
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
32
+ locode = locode.gsub(' ', '').upcase
33
+ includes(:country).find_by(city_code: locode[2..4], countries: { code: locode[0..1] })
35
34
  end
36
35
 
37
36
  def as_json options = {}
@@ -1,3 +1,3 @@
1
1
  module UnLocode
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
@@ -94,13 +94,26 @@ describe UnLocode::Locode do
94
94
  let!(:country) { UnLocode::Country.create name: 'NETHERLANDS', code: 'NL' }
95
95
  let!(:location) { UnLocode::Locode.create name: 'Venlo', city_code: 'VEN', country: country }
96
96
 
97
- context 'with supported functions' do
97
+ context 'with supported functions and space in search' do
98
98
  subject { UnLocode::Locode.find_by_locode(search_term) }
99
99
  let(:search_term) { 'NL VEN' }
100
-
100
+ its(:city_code) { should eql('VEN') }
101
101
  its(:name) { should eql('Venlo') }
102
102
  its(:country) { should eql(country) }
103
103
  end
104
+ context 'with supported functions with actual space-less locode' do
105
+ subject { UnLocode::Locode.find_by_locode(search_term) }
106
+ let(:search_term) { 'NLVEN' }
107
+ its(:city_code) { should eql('VEN') }
108
+ its(:name) { should eql('Venlo') }
109
+ its(:country) { should eql(country) }
110
+ end
111
+ context 'with supported functions with mixed case locode' do
112
+ subject { UnLocode::Locode.find_by_locode(search_term) }
113
+ let(:search_term) { 'NlVen' }
114
+ its(:city_code) { should eql('VEN') }
115
+ end
116
+
104
117
  end
105
118
  end
106
119
 
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
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michel de Graaf
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2015-07-10 00:00:00.000000000 Z
15
+ date: 2015-07-17 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: bundler
@@ -125,7 +125,9 @@ extra_rdoc_files: []
125
125
  files:
126
126
  - ".DS_Store"
127
127
  - ".gitignore"
128
+ - ".hound.yml"
128
129
  - ".rspec"
130
+ - ".ruby-style.yml"
129
131
  - ".ruby-version"
130
132
  - ".travis.yml"
131
133
  - Gemfile