class Traveller
Attributes
city[RW]
Parse locations for fun!
Example:
>> traveller = Traveller.new("canton, oh 44720") >> traveller.state => "Ohio"
Arguments:
input: (String)
latitude[RW]
Parse locations for fun!
Example:
>> traveller = Traveller.new("canton, oh 44720") >> traveller.state => "Ohio"
Arguments:
input: (String)
longitude[RW]
Parse locations for fun!
Example:
>> traveller = Traveller.new("canton, oh 44720") >> traveller.state => "Ohio"
Arguments:
input: (String)
state[RW]
Parse locations for fun!
Example:
>> traveller = Traveller.new("canton, oh 44720") >> traveller.state => "Ohio"
Arguments:
input: (String)
state_abbreviation[RW]
Parse locations for fun!
Example:
>> traveller = Traveller.new("canton, oh 44720") >> traveller.state => "Ohio"
Arguments:
input: (String)
zip[RW]
Parse locations for fun!
Example:
>> traveller = Traveller.new("canton, oh 44720") >> traveller.state => "Ohio"
Arguments:
input: (String)
Public Class Methods
new(input)
click to toggle source
# File lib/traveller.rb, line 14 def initialize(input) @input = input @input.downcase! @input.gsub!(/[,]/, '') # Begin parsing parse_zip parse_state_and_abbreviation parse_city end
Public Instance Methods
assign_state_and_abbriviation(value)
click to toggle source
# File lib/traveller.rb, line 50 def assign_state_and_abbriviation(value) 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' } @input.sub!(/\b#{value}\b/, '') unless value.nil? if value.length == 2 @state = state_flashcards.invert[value] @state_abbreviation = value else @state = value @state_abbreviation = state_flashcards[value] end end
parse_city()
click to toggle source
# File lib/traveller.rb, line 62 def parse_city @city = @input.strip end
parse_state_and_abbreviation()
click to toggle source
# File lib/traveller.rb, line 31 def parse_state_and_abbreviation 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'] 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 dakota', 'west virginia' ] 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'] input_tokens = @input.split abbreviations.each { |state| assign_state_and_abbriviation(state) and return if input_tokens.include?(state) } multi_word_states.each { |state| assign_state_and_abbriviation(state) and return if @input.include?(state) } single_word_states.each { |state| assign_state_and_abbriviation(state) and return if input_tokens.include?(state) } end
parse_zip()
click to toggle source
# File lib/traveller.rb, line 25 def parse_zip zip = @input[/\b([0-9]{5})\b/] @input.sub!(zip, '') unless zip.nil? @zip = zip end