state_geo_tools 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a38cb80e205d57912a0cb0f2a0154c731613f168
4
- data.tar.gz: 9e52f549e48190731110d2658fffe25396f75149
2
+ SHA256:
3
+ metadata.gz: 3a797992d9fd66ce615c2ae196fe5ebea5f7f0b3e5d7ecc0d11ae9fd476cf8dc
4
+ data.tar.gz: c58596ab153652945353cbec8ecbea833f37a6732514329ae40523fb0f29ed93
5
5
  SHA512:
6
- metadata.gz: '00469303beafc0947f1cb362131ff8df968b0e4d617d53a655209c66567c003982fed0fe1a4450f53aee46216790ed282906ebf221908d31ad4caff0db3cc2df'
7
- data.tar.gz: 60526aa38bbd99b4fcaa51fd89185c9f6b1b4295fbba69d7e49e9533fb13b99ddbb0d6c64c175c5d4ef50dea138921987789f589efdfa505e8b7159059f6ea2e
6
+ metadata.gz: 579fd09dde7ce7b541483c92bb47fbdd8215b010e63a09d336db937a3cb36b7c23c641d1b0ac7ecc6adcbe44bcb00e9437de4098354aeceee70c62394d484ef1
7
+ data.tar.gz: 6a047446835b663b9b6671d2b20903932aa9acc5f9b1386e2a26d6e020e59f0da10dcdcbcc3b0ebd8b303b4ce5295ae475cebad6d977d7910e55b614cb08416a
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.0
data/.travis.yml CHANGED
@@ -1,5 +1,7 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.4.1
5
- before_install: gem install bundler -v 1.14.6
4
+ - 2.4
5
+ - 2.5
6
+ - 2.6
7
+ before_install: gem install bundler -v 1.17.2
data/README.md CHANGED
@@ -6,10 +6,7 @@ These are tools to save me from having to copy and paste the same state
6
6
  constants across tools when I need to iterate thru or populate a list of
7
7
  states (which is basically all the time).
8
8
 
9
- TODOS:
10
-
11
- * option rename DC to whatever bonkers things people put down in text
12
- * count DC (and other states, I guess) when AKA strings show up
9
+ [Docs are here.](https://www.rubydoc.info/github/colinxfleming/state_geo_tools/master)
13
10
 
14
11
  ## Installation
15
12
 
@@ -55,6 +52,18 @@ Prefer a two letter code instead of the full string? You're covered:
55
52
  => ["AS", "FM", "GU", "MH", "MP", "PW", "PR", "VI"]
56
53
  ```
57
54
 
55
+ ### Toploading
56
+
57
+ For convenience, an optional argument is provided to pull certain items up to
58
+ the top of a list. Pass `topload: [elements]` to `states`, `territories`,
59
+ `state_codes`, or `territory_codes` to pull a few to the front. For example:
60
+
61
+ ```rb
62
+ > require 'state_geo_tools'
63
+ > StateGeoTools.state_codes(topload: ['MI', 'DC', 'TX'])
64
+ => ["MI", "DC", "TX", "AR", "CA", "CO", "CT", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "UT", "VT", "VA", "WA", "WV", "WI", "AL", "WY", "AK", "AZ"]
65
+ ```
66
+
58
67
  ### Count instances of states in a string
59
68
 
60
69
  There is a convenience method provided to scan a string for state or territory
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StateGeoTools
4
+ # Sometimes you want to pull some entries up.
5
+ module Toploader
6
+ TOPLOAD_ERROR = 'is not in the set and not toploadable'
7
+
8
+ class NotInSetError < StandardError; end
9
+
10
+ def topload_items(set, topload)
11
+ topload.each do |x|
12
+ raise(NotInSetError, "#{x} #{TOPLOAD_ERROR}") unless set.include?(x)
13
+ end
14
+
15
+ # If not in the topload set, offset the ordering by a few hundred so it
16
+ # maintains its current order
17
+ set.sort_by { |item| topload.index(item) || (500 + set.index(item)) }
18
+ end
19
+ end
20
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StateGeoTools
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -4,35 +4,49 @@ require 'state_geo_tools/version'
4
4
  require 'state_geo_tools/state_constants'
5
5
  require 'state_geo_tools/territory_constants'
6
6
  require 'state_geo_tools/counters'
7
+ require 'state_geo_tools/toploader'
7
8
 
8
9
  # Because I got sick of copying and pasting arrays of states everywhere, this
9
10
  # utility provides some convenience methods to get a full set of US states and
10
11
  # territories. It also includes a pair of convenience methods.
11
12
  #
12
13
  # The utility modules are all public, in the event that one should need to
13
- # use them in a slightly different way, but the common use case is in this
14
+ # use them in a slightly different way, but the common use case is in this.
14
15
  #
15
16
  # See the README for examples.
16
17
  module StateGeoTools
17
18
  extend StateGeoTools::Counters
19
+ extend StateGeoTools::Toploader
18
20
 
19
21
  # Return an array of states and the District of Columbia.
20
- def self.states
22
+ # Optionally pull items up top with a topload array kwarg.
23
+ def self.states(topload: nil)
24
+ return topload_items(States::STATES, topload) if topload
25
+
21
26
  States::STATES
22
27
  end
23
28
 
24
29
  # Return an array of two-letter state codes, and DC.
25
- def self.state_codes
30
+ # Optionally pull items up top with a topload array kwarg.
31
+ def self.state_codes(topload: nil)
32
+ return topload_items(States::STATE_CODES, topload) if topload
33
+
26
34
  States::STATE_CODES
27
35
  end
28
36
 
29
37
  # Return an array of US territories.
30
- def self.territories
38
+ # Optionally pull items up top with a topload array kwarg.
39
+ def self.territories(topload: nil)
40
+ return topload_items(Territories::TERRITORIES, topload) if topload
41
+
31
42
  Territories::TERRITORIES
32
43
  end
33
44
 
34
45
  # Return an array of two-letter US territory codes.
35
- def self.territory_codes
46
+ # Optionally pull items up top with a topload array kwarg.
47
+ def self.territory_codes(topload: nil)
48
+ return topload_items(Territories::TERRITORY_CODES, topload) if topload
49
+
36
50
  Territories::TERRITORY_CODES
37
51
  end
38
52
 
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ['lib']
24
24
 
25
- spec.add_development_dependency 'bundler', '~> 1.14'
26
- spec.add_development_dependency 'minitest', '~> 5.0'
27
- spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'bundler', '~> 1.17'
26
+ spec.add_development_dependency 'minitest', '~> 5'
27
+ spec.add_development_dependency 'rake', '~> 12'
28
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: state_geo_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - colinxfleming
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-18 00:00:00.000000000 Z
11
+ date: 2019-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.14'
19
+ version: '1.17'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.14'
26
+ version: '1.17'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '5.0'
33
+ version: '5'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '5.0'
40
+ version: '5'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '12'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '12'
55
55
  description: I got sick of copying the same US states constant.
56
56
  email:
57
57
  - c3flemin@gmail.com
@@ -61,6 +61,7 @@ extra_rdoc_files: []
61
61
  files:
62
62
  - ".gitignore"
63
63
  - ".rubocop.yml"
64
+ - ".ruby-version"
64
65
  - ".travis.yml"
65
66
  - Gemfile
66
67
  - LICENSE.txt
@@ -72,6 +73,7 @@ files:
72
73
  - lib/state_geo_tools/counters.rb
73
74
  - lib/state_geo_tools/state_constants.rb
74
75
  - lib/state_geo_tools/territory_constants.rb
76
+ - lib/state_geo_tools/toploader.rb
75
77
  - lib/state_geo_tools/version.rb
76
78
  - state_geo_tools.gemspec
77
79
  homepage: https://github.com/colinxfleming/state_geo_tools
@@ -93,8 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
95
  - !ruby/object:Gem::Version
94
96
  version: '0'
95
97
  requirements: []
96
- rubyforge_project:
97
- rubygems_version: 2.6.14
98
+ rubygems_version: 3.0.1
98
99
  signing_key:
99
100
  specification_version: 4
100
101
  summary: A US geography/state utility.