traveller 0.0.001
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/traveller.rb +68 -0
- metadata +59 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e94b7ecc28fdd4749f124cfa869036d1c3900644
|
4
|
+
data.tar.gz: 84b2f3e6af0b81053c57caf215dcad0e0257af4e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5c96a44cb03c6cb703f9ceac07465c633140546c17cb094df3d0aa8be412208dd28feacb94d14a9f9c528c74c5fe01af467bed2e711a98b5e044ac27e18d7dd3
|
7
|
+
data.tar.gz: 677ea28b12b1a23475dc5722e8dab0532407437d1b0a1855a78bfbd7e7f3124e3f5adfcca86d34efe7b14c8e9198c81844d2ee61c8a28133b9f429e17629116e
|
data/lib/traveller.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
class Traveller
|
2
|
+
# Parse locations for fun!
|
3
|
+
#
|
4
|
+
# Example:
|
5
|
+
# >> traveller = Traveller.new("canton, oh 44720")
|
6
|
+
# >> traveller.state
|
7
|
+
# => "Ohio"
|
8
|
+
#
|
9
|
+
# Arguments:
|
10
|
+
# input: (String)
|
11
|
+
|
12
|
+
attr_reader :city, :state, :latitude, :longitude, :zip, :state_abbreviation
|
13
|
+
|
14
|
+
def initialize(input)
|
15
|
+
@input = input
|
16
|
+
@input.downcase!
|
17
|
+
@input.gsub!(/[,]/, '')
|
18
|
+
|
19
|
+
# Begin parsing
|
20
|
+
parse_zip
|
21
|
+
parse_state_and_abbreviation
|
22
|
+
parse_city
|
23
|
+
end
|
24
|
+
|
25
|
+
def parse_zip
|
26
|
+
zip = @input[/[0-9]{5}/]
|
27
|
+
@input.sub!(zip, '') unless zip.nil?
|
28
|
+
@zip = zip
|
29
|
+
end
|
30
|
+
|
31
|
+
def parse_state_and_abbreviation
|
32
|
+
single_word_states = ['alabama', 'alaska', 'arizona', 'arkansas', 'california', 'colorado', 'connecticut', 'delaware', 'florida', 'georgia', 'hawaii', 'idaho', 'illinois', 'indiana', 'iowa', 'kansas', 'kentucky', 'louisiana', 'maine', 'maryland', 'massachusetts', 'michigan', 'minnesota', 'mississippi', 'missouri', 'montana', 'nebraska', 'nevada', 'ohio', 'oklahoma', 'oregon', 'pennsylvania', 'tennessee', 'texas', 'utah', 'vermont', 'virginia', 'washington', 'wisconsin', 'wyoming']
|
33
|
+
multi_word_states = ['district of columbia', 'new hampshire', 'new jersey', 'new mexico', 'new york', 'north carolina', 'north dakota', 'puerto rico', 'rhode island', 'south carolina', 'south daktoa', 'west virginia' ]
|
34
|
+
abbreviations = ['al', 'ak', 'az', 'ar', 'ca', 'co', 'ct', 'de', 'dc', 'fl', 'ga', 'hi', 'id', 'il', 'in', 'ia', 'ks', 'ky', 'la', 'me', 'md', 'ma', 'mi', 'mn', 'ms', 'mo', 'mt', 'ne', 'nv', 'nh', 'nj', 'nm', 'ny', 'nc', 'nd', 'oh', 'ok', 'or', 'pa', 'pr', 'ri', 'sc', 'sd', 'tn', 'tx', 'ut', 'vt', 'va', 'wa', 'wv', 'wi', 'wy']
|
35
|
+
input_tokens = @input.split
|
36
|
+
|
37
|
+
multi_word_states.each { |state|
|
38
|
+
assign_state_and_abbriviation(state) and return if @input.include?(state)
|
39
|
+
}
|
40
|
+
|
41
|
+
single_word_states.each { |state|
|
42
|
+
assign_state_and_abbriviation(state) and return if input_tokens.include?(state)
|
43
|
+
}
|
44
|
+
|
45
|
+
abbreviations.each { |state|
|
46
|
+
assign_state_and_abbriviation(state) and return if input_tokens.include?(state)
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
def assign_state_and_abbriviation(value)
|
51
|
+
state_flashcards = { 'alabama' => 'al', 'alaska' => 'ak', 'america samoa' => 'as', 'arizona' => 'az', 'arkansas' => 'ar', 'california' => 'ca', 'colorado' => 'co', 'connecticut' => 'ct', 'delaware' => 'de', 'district of columbia' => 'dc', 'micronesia1' => 'fm', 'florida' => 'fl', 'georgia' => 'ga', 'guam' => 'gu', 'hawaii' => 'hi', 'idaho' => 'id', 'illinois' => 'il', 'indiana' => 'in', 'iowa' => 'ia', 'kansas' => 'ks', 'kentucky' => 'ky', 'louisiana' => 'la', 'maine' => 'me', 'marshall isands' => 'mh', 'maryland' => 'md', 'massachusetts' => 'ma', 'michigan' => 'mi', 'minnesota' => 'mn', 'mississippi' => 'ms', 'missouri' => 'mo', 'montana' => 'mt', 'nebraska' => 'ne', 'nevada' => 'nv', 'new hampshire' => 'nh', 'new jersey' => 'nj', 'new mexico' => 'nm', 'new york' => 'ny', 'north carolina' => 'nc', 'north dakota' => 'nd', 'ohio' => 'oh', 'oklahoma' => 'ok', 'oregon' => 'or', 'palau' => 'pw', 'pennsylvania' => 'pa', 'puerto rico' => 'pr', 'rhode island' => 'ri', 'south carolina' => 'sc', 'south dakota' => 'sd', 'tennessee' => 'tn', 'texas' => 'tx', 'utah' => 'ut', 'vermont' => 'vt', 'virgin island' => 'vi', 'virginia' => 'va', 'washington' => 'wa', 'west virginia' => 'wv', 'wisconsin' => 'wi', 'wyoming' => 'wy' }
|
52
|
+
@input.sub!(value, '') unless value.nil?
|
53
|
+
|
54
|
+
if value.length == 2
|
55
|
+
@state = state_flashcards.invert[value]
|
56
|
+
@state_abbreviation = value
|
57
|
+
else
|
58
|
+
@state = value
|
59
|
+
@state_abbreviation = state_flashcards[value]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def parse_city
|
64
|
+
@city = @input.strip
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: traveller
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.001
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kyle Dreger
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Traveller parses location-based strings and exposes their city, state,
|
28
|
+
zip code, latitude, and longitude.
|
29
|
+
email: dregerkq@mountunion.edu
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- lib/traveller.rb
|
35
|
+
homepage: https://github.com/kyledreger/traveller
|
36
|
+
licenses:
|
37
|
+
- MIT
|
38
|
+
metadata: {}
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 2.2.2
|
56
|
+
signing_key:
|
57
|
+
specification_version: 4
|
58
|
+
summary: Find that location.
|
59
|
+
test_files: []
|