geolookup 0.6.2 → 0.6.4

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: 46ae92eca6934c5c93d7507741b0064f65b81157
4
- data.tar.gz: 59881c0780b02a53d5f0bc0e38f3b8262dea624c
3
+ metadata.gz: c2448f87284821120335883ab119ff7267a562bc
4
+ data.tar.gz: 00865ae14c0a0f6946e1a670434da19c48aeb783
5
5
  SHA512:
6
- metadata.gz: e607715087e52aac9deb6c39db1e36acb5ef1695287753bf91d152bb0c202f84f0d1560e3ee0ef090e93734a21cf3bffb1e5a7b304b6641b805df89098714f27
7
- data.tar.gz: 3bb0c3762db66561c1805d3b3a810ad258c1c46aaa77d23523613424d40e6b8c716e72888d8a4c2d3bfa76c05e45cfa1d4a0eea4356bf08f44c45b892ebdb223
6
+ metadata.gz: 5ea4ab17b773b6a6ad344c13efe857ed1240beb39471f65551c949574802677a1fd58792af405431199b38386476a62e206110c07617bf4e43f54ef8bfba1d4e
7
+ data.tar.gz: a1b0d38ad66f04f85df8e71cd898c05d8db9032dfd1f9e423c868b7c7a3f470c4293ef7f6b2d3617cc252e6585f28816a8cdb99cee8c455253f3dd15c2f3752e
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ *.idea
@@ -1,3 +1,9 @@
1
+ === 0.6.4
2
+ - Changed the word 'ignored' to the more appropriate, general term 'territory'
3
+
4
+ === 0.6.3
5
+ - Added ignored? functionality
6
+
1
7
  === 0.6.2
2
8
  - Added ignored_states and country_to_phone_code and associated methods
3
9
 
data/README.md CHANGED
@@ -85,6 +85,34 @@ Geolookup::USA::State.abbreviations_and_names
85
85
  Geolookup::USA::State.codes
86
86
  # => [1, 2, 4, ...]
87
87
 
88
+ # US Territory State Codes
89
+ Geolookup::USA::State.territory_state_codes
90
+ # => [60, 66, 69, ...]
91
+
92
+ # US Territory State Names
93
+ Geolookup::USA::State.territory_state_names
94
+ # => ["American Samoa", "Guam", ...]
95
+
96
+ # Determine if state is territory
97
+
98
+ # With code
99
+ Geolookup::USA::State.territory?(60)
100
+ # => true
101
+
102
+ Geolookup::USA::State.territory?('60')
103
+ # => true
104
+
105
+ # With state name
106
+ Geolookup::USA::State.territory?('Guam')
107
+ # => true
108
+
109
+ # With state abbreviation
110
+ Geolookup::USA::State.territory?('GU')
111
+ # => true
112
+
113
+ Geolookup::USA::State.territory?('AZ')
114
+ # => false
115
+
88
116
  # US County Examples:
89
117
 
90
118
  # Given a state code and county code return the county name
@@ -7,7 +7,7 @@ module Geolookup
7
7
  STATE_NAME_TO_CODE_FILE = 'STATE_NAME_TO_CODE.yml'
8
8
  STATE_ABBREVIATION_TO_NAME_FILE = 'STATE_FULL_STATE_NAMES.yml'
9
9
  STATE_LAT_LONG_FILE = 'STATE_LAT_LONG.yml'
10
- IGNORED_STATES_FILE = 'IGNORED_STATES.yml'
10
+ TERRITORY_STATES_FILE = 'TERRITORY_STATES.yml'
11
11
  DOMESTIC_STATE_CUTOFF = 56
12
12
 
13
13
  @state_code_to_full
@@ -15,7 +15,7 @@ module Geolookup
15
15
  @state_name_to_code
16
16
  @state_abbreviation_to_name
17
17
  @state_lat_long
18
- @ignored_states
18
+ @territory_states
19
19
  @domestic_state_code_to_name
20
20
  @domestic_state_code_to_abbreviation
21
21
  ###################################################################
@@ -167,25 +167,46 @@ module Geolookup
167
167
  end
168
168
 
169
169
  ###################################################################
170
- # self.ignored_state_codes
170
+ # self.territory_state_codes
171
171
  #
172
- # Returns an array of ignored state codes
172
+ # Returns an array of territory state codes
173
173
  #
174
- def self.ignored_state_codes
175
- @ignored_states ||= Geolookup.load_hash_from_file(IGNORED_STATES_FILE)
176
- @ignored_states.keys
174
+ def self.territory_state_codes
175
+ @territory_states ||= Geolookup.load_hash_from_file(TERRITORY_STATES_FILE)
176
+ @territory_states.keys
177
177
  end
178
178
 
179
179
  ###################################################################
180
- # self.ignored_state_names
180
+ # self.territory_state_names
181
181
  #
182
- # Returns an array of ignored state names
182
+ # Returns an array of territory state names
183
183
  #
184
- def self.ignored_state_names
185
- @ignored_states ||= Geolookup.load_hash_from_file(IGNORED_STATES_FILE)
186
- @ignored_states.values
184
+ def self.territory_state_names
185
+ @territory_states ||= Geolookup.load_hash_from_file(TERRITORY_STATES_FILE)
186
+ @territory_states.values
187
187
  end
188
188
 
189
+ ###################################################################
190
+ # self.territory?
191
+ #
192
+ # Given a state name, abbreviation, or code, returns true if the
193
+ # state should be territory and false otherwise.
194
+ #
195
+ def self.territory?(state)
196
+ @territory_states ||= Geolookup.load_hash_from_file(TERRITORY_STATES_FILE)
197
+ titlized_state_name = state.to_s.split.map(&:capitalize).join(' ')
198
+
199
+ is_territory_state_name = territory_state_names.include? titlized_state_name
200
+ is_territory_state_code = territory_state_codes.include? state.to_i
201
+ is_territory_state_abbreviation = territory_state_names.include? abbreviation_to_name(state)
202
+
203
+ is_territory_state_name || is_territory_state_code || is_territory_state_abbreviation
204
+ end
205
+
206
+ def self.ignored_state_codes() territory_state_codes end
207
+ def self.ignored_state_names() territory_state_names end
208
+ def self.ignored?(state) territory?(state) end
209
+
189
210
  class << self
190
211
  alias :abbreviation_to_code :name_to_code
191
212
  alias :abbreviation_to_lat_long :name_to_lat_long
@@ -1,3 +1,3 @@
1
1
  module Geolookup
2
- VERSION = '0.6.2'
2
+ VERSION = '0.6.4'
3
3
  end
@@ -38,15 +38,15 @@ describe "Geolookup::USA::State" do
38
38
  end
39
39
  end
40
40
 
41
- describe "#ignored_state_codes" do
42
- it 'should return an array of ignored state codes' do
43
- expect(Geolookup::USA::State.ignored_state_codes).to include(60)
41
+ describe "#territory_state_codes" do
42
+ it 'should return an array of territory state codes' do
43
+ expect(Geolookup::USA::State.territory_state_codes).to include(60)
44
44
  end
45
45
  end
46
46
 
47
- describe "#ignored_state_names" do
48
- it 'should return an array of ignored state names' do
49
- expect(Geolookup::USA::State.ignored_state_names).to include("American Samoa")
47
+ describe "#territory_state_names" do
48
+ it 'should return an array of territory state names' do
49
+ expect(Geolookup::USA::State.territory_state_names).to include("American Samoa")
50
50
  end
51
51
  end
52
52
 
@@ -179,4 +179,115 @@ describe "Geolookup::USA::State" do
179
179
  expect(Geolookup::USA::State.domestic_names).to_not include("Guam")
180
180
  end
181
181
  end
182
+
183
+ describe '#territory?' do
184
+ context 'input is a code' do
185
+ context 'code is an integer' do
186
+ context 'state is territory' do
187
+ it 'returns true' do
188
+ state_code = 60
189
+ expect(Geolookup::USA::State.territory?(state_code)).to be true
190
+ end
191
+ end
192
+ context 'state is not territory' do
193
+ it 'returns false' do
194
+ state_code = 1
195
+ expect(Geolookup::USA::State.territory?(state_code)).to be false
196
+ end
197
+ end
198
+ end
199
+ context 'code is a string' do
200
+ context 'state is territory' do
201
+ it 'returns true' do
202
+ state_code = '66'
203
+ expect(Geolookup::USA::State.territory?(state_code)).to be true
204
+ end
205
+ end
206
+ context 'state is not territory' do
207
+ it 'returns false' do
208
+ state_code = '2'
209
+ expect(Geolookup::USA::State.territory?(state_code)).to be false
210
+ end
211
+ end
212
+ end
213
+ end
214
+ context 'input is an abbreviation' do
215
+ context 'casing is all upcase' do
216
+ context 'state is territory' do
217
+ it 'returns true' do
218
+ state_abbreviation = 'MP'
219
+ expect(Geolookup::USA::State.territory?(state_abbreviation)).to be true
220
+ end
221
+ end
222
+ context 'state is not territory' do
223
+ it 'returns false' do
224
+ state_abbreviation = 'AZ'
225
+ expect(Geolookup::USA::State.territory?(state_abbreviation)).to be false
226
+ end
227
+ end
228
+ end
229
+ context 'casing is mixed' do
230
+ context 'state is territory' do
231
+ it 'returns true' do
232
+ state_abbreviation = 'vI'
233
+ expect(Geolookup::USA::State.territory?(state_abbreviation)).to be true
234
+ end
235
+ end
236
+ context 'state is not territory' do
237
+ it 'returns false' do
238
+ state_abbreviation = 'Ar'
239
+ expect(Geolookup::USA::State.territory?(state_abbreviation)).to be false
240
+ end
241
+ end
242
+ end
243
+ end
244
+ context 'input is a state name' do
245
+ context 'casing is all upcase' do
246
+ context 'state is territory' do
247
+ it 'returns true' do
248
+ state_name = 'AMERICAN SAMOA'
249
+ expect(Geolookup::USA::State.territory?(state_name)).to be true
250
+ end
251
+ end
252
+ context 'state is not territory' do
253
+ it 'returns false' do
254
+ state_name = 'CALIFORNIA'
255
+ expect(Geolookup::USA::State.territory?(state_name)).to be false
256
+ end
257
+ end
258
+ end
259
+ context 'casing is mixed' do
260
+ context 'state is territory' do
261
+ it 'returns true' do
262
+ state_name = 'Guam'
263
+ expect(Geolookup::USA::State.territory?(state_name)).to be true
264
+ end
265
+ end
266
+ context 'state is not territory' do
267
+ it 'returns false' do
268
+ state_name = 'CoLoRaDo'
269
+ expect(Geolookup::USA::State.territory?(state_name)).to be false
270
+ end
271
+ end
272
+ end
273
+ end
274
+ end
275
+
276
+ describe '#ignored_state_names' do
277
+ it 'returns territory_state_names' do
278
+ expect(Geolookup::USA::State.ignored_state_names).to eq Geolookup::USA::State.territory_state_names
279
+ end
280
+ end
281
+
282
+ describe '#ignored_state_codes' do
283
+ it 'returns territory_state_codes' do
284
+ expect(Geolookup::USA::State.ignored_state_codes).to eq Geolookup::USA::State.territory_state_codes
285
+ end
286
+ end
287
+
288
+ describe '#ignored?' do
289
+ it 'returns territory' do
290
+ expect(Geolookup::USA::State.ignored?('ca')).to eq Geolookup::USA::State.territory?('ca')
291
+ end
292
+ end
182
293
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geolookup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Austin Fonacier
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2016-05-20 00:00:00.000000000 Z
14
+ date: 2016-11-16 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler
@@ -83,7 +83,6 @@ files:
83
83
  - lib/data/COUNTY_IGNORED_STATES.yml
84
84
  - lib/data/COUNTY_LAT_LONG.yml
85
85
  - lib/data/COUNTY_NAME_TO_CODE.yml
86
- - lib/data/IGNORED_STATES.yml
87
86
  - lib/data/METRO_CODE_TO_NAME.yml
88
87
  - lib/data/STATE_CODE_TO_DISPLAY_NAME.yml
89
88
  - lib/data/STATE_CODE_TO_FULL.yml
@@ -91,6 +90,7 @@ files:
91
90
  - lib/data/STATE_FULL_STATE_NAMES.yml
92
91
  - lib/data/STATE_LAT_LONG.yml
93
92
  - lib/data/STATE_NAME_TO_CODE.yml
93
+ - lib/data/TERRITORY_STATES.yml
94
94
  - lib/data/ZIP_LAT_LONG.yml
95
95
  - lib/geolookup.rb
96
96
  - lib/geolookup/country.rb