state_geo_tools 0.2.0 → 1.0.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 +4 -4
- data/.rubocop.yml +1 -1
- data/.ruby-version +1 -1
- data/.travis.yml +0 -1
- data/README.md +0 -24
- data/lib/state_geo_tools.rb +0 -2
- data/lib/state_geo_tools/state_constants.rb +1 -1
- data/lib/state_geo_tools/version.rb +1 -1
- data/state_geo_tools.gemspec +0 -1
- metadata +3 -18
- data/lib/state_geo_tools/counters.rb +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b480633985bd7d4cb27c5bf388af65131e508dbd0b86f22f39d4cfd7fd3a4a84
|
4
|
+
data.tar.gz: 7a6ee02e1318c8219eca2ea4b72950dd481934f2d8ab94c79a8d8ee897611005
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a3d61d315892d88cd6f2ae41eca289f93ff58d1946f05232d5c09e95333bbfda369b70eb7fd7b300f1382073d9ea6555cf2c55dec459003ccba0948384afd74
|
7
|
+
data.tar.gz: 97dc80c94ce6cef26ba58c56a51fc4d5fe338d6dba9272cba8d2587c06a16735e1e744b1eeff525096bc47207141b0c08a0d4859840e971188201be69eddd8a9
|
data/.rubocop.yml
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
AllCops:
|
2
|
-
TargetRubyVersion: 2.
|
2
|
+
TargetRubyVersion: 2.6.3
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.6.
|
1
|
+
2.6.3
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -64,30 +64,6 @@ the top of a list. Pass `topload: [elements]` to `states`, `territories`,
|
|
64
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
65
|
```
|
66
66
|
|
67
|
-
### Count instances of states in a string
|
68
|
-
|
69
|
-
There is a convenience method provided to scan a string for state or territory
|
70
|
-
names and return a count.
|
71
|
-
|
72
|
-
Coming eventually: Handling all the aliases for Washington, DC.
|
73
|
-
|
74
|
-
```rb
|
75
|
-
> require 'state_geo_tools'
|
76
|
-
> StateGeoTools.count_states_in('Pantera were from Texas, I saw them in Indiana')
|
77
|
-
=> {"Texas"=>1, "Indiana"=>1}
|
78
|
-
|
79
|
-
> StateGeoTools.count_territories_in('The Simpsons are going to Guam!')
|
80
|
-
=> {"Guam"=>1}
|
81
|
-
|
82
|
-
# There's some special handling for Washington/Washington DC and Virginia/West
|
83
|
-
# Virginia. It doesn't work flawlessly yet, so heads up!
|
84
|
-
> StateGeoTools.count_states_in('Virginia and West Virginia are for lovers')
|
85
|
-
=> {"West Virginia"=>1, "Virginia"=>1}
|
86
|
-
|
87
|
-
> StateGeoTools.count_states_in('Washington and Washington, DC are on opposite sides of the country')
|
88
|
-
=> {"Washington"=>1}
|
89
|
-
```
|
90
|
-
|
91
67
|
## Development
|
92
68
|
|
93
69
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
data/lib/state_geo_tools.rb
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
require 'state_geo_tools/version'
|
4
4
|
require 'state_geo_tools/state_constants'
|
5
5
|
require 'state_geo_tools/territory_constants'
|
6
|
-
require 'state_geo_tools/counters'
|
7
6
|
require 'state_geo_tools/toploader'
|
8
7
|
|
9
8
|
# Because I got sick of copying and pasting arrays of states everywhere, this
|
@@ -15,7 +14,6 @@ require 'state_geo_tools/toploader'
|
|
15
14
|
#
|
16
15
|
# See the README for examples.
|
17
16
|
module StateGeoTools
|
18
|
-
extend StateGeoTools::Counters
|
19
17
|
extend StateGeoTools::Toploader
|
20
18
|
|
21
19
|
# Return an array of states and the District of Columbia.
|
@@ -14,7 +14,7 @@ module StateGeoTools
|
|
14
14
|
{ name: 'Connecticut', code: 'CT' },
|
15
15
|
{ name: 'Delaware', code: 'DE' },
|
16
16
|
# Statehood for DC: An opinion I am expressing in code by including DC
|
17
|
-
{ name: 'District of Columbia', code: 'DC'
|
17
|
+
{ name: 'District of Columbia', code: 'DC' },
|
18
18
|
{ name: 'Florida', code: 'FL' },
|
19
19
|
{ name: 'Georgia', code: 'GA' },
|
20
20
|
{ name: 'Hawaii', code: 'HI' },
|
data/state_geo_tools.gemspec
CHANGED
@@ -22,7 +22,6 @@ 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.17'
|
26
25
|
spec.add_development_dependency 'minitest', '~> 5'
|
27
26
|
spec.add_development_dependency 'rake', '~> 12'
|
28
27
|
end
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: state_geo_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- colinxfleming
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: bundler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.17'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.17'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: minitest
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,7 +56,6 @@ files:
|
|
70
56
|
- bin/console
|
71
57
|
- bin/setup
|
72
58
|
- lib/state_geo_tools.rb
|
73
|
-
- lib/state_geo_tools/counters.rb
|
74
59
|
- lib/state_geo_tools/state_constants.rb
|
75
60
|
- lib/state_geo_tools/territory_constants.rb
|
76
61
|
- lib/state_geo_tools/toploader.rb
|
@@ -95,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
80
|
- !ruby/object:Gem::Version
|
96
81
|
version: '0'
|
97
82
|
requirements: []
|
98
|
-
rubygems_version: 3.0.
|
83
|
+
rubygems_version: 3.0.3
|
99
84
|
signing_key:
|
100
85
|
specification_version: 4
|
101
86
|
summary: A US geography/state utility.
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module StateGeoTools
|
4
|
-
# Methods for counting instances in a string.
|
5
|
-
module Counters
|
6
|
-
# Count appearances of const's elements in the string.
|
7
|
-
#
|
8
|
-
# Const can be any array of strings, but we generally use the list of
|
9
|
-
# states and territories.
|
10
|
-
#
|
11
|
-
# Returns a single hash with the const element as the keys. No zeroes.
|
12
|
-
def count_instances(string, const)
|
13
|
-
instances = const.sort.map do |geo|
|
14
|
-
{ geo.to_s => string.scan(geo_regex(geo)).count }
|
15
|
-
end
|
16
|
-
instances.reduce { |x, y| x.merge(y) }
|
17
|
-
.delete_if { |_, v| v.zero? }
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def geo_regex(geo)
|
23
|
-
# Need special handling for the great state of Virginia,
|
24
|
-
# because of West Virginia.
|
25
|
-
return /(?<!west )virginia/i if geo == 'Virginia'
|
26
|
-
return /washington(?!, D\.*C\.*)/i if geo == 'Washington'
|
27
|
-
/#{geo}/i
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|