Skip to content

Instantly share code, notes, and snippets.

@shinobcrc
Forked from davidvandusen/state_info.rb
Last active June 22, 2016 19:04
Show Gist options
  • Save shinobcrc/baac5a9ded1d220f2c8da4fec62179ca to your computer and use it in GitHub Desktop.
Save shinobcrc/baac5a9ded1d220f2c8da4fec62179ca to your computer and use it in GitHub Desktop.
@states = {
OR: 'Oregon',
FL: 'Florida',
CA: 'California',
NY: 'New York',
MI: 'Michigan'
}
@states[:TX] = "Texas"
@states[:GA] = "Georgia"
# puts @states
@cities = {
CA: "Compton, Oakland, San Francisco",
FL: "Miami, Orlando",
OR: "Portland"
}
# @cities.each do |key, value|
# puts value
# end
def describe_state(state_code)
return "#{state_code} is for #{@states[state_code]}. It has major cities such as #{@cities[state_code]}"
end
# puts describe_state(:CA)
@taxes = {
CA: 4.5,
MI: 6.0,
FL: 12.0
}
def calculate_tax(state_code, cost)
tax_rate = @taxes[state_code].to_f
total_cost = (cost.to_f * tax_rate/100).round(2)
end
# puts calculate_tax(:CA, 44.53)
def find_state_for_city(city_name)
state_code = nil
@cities.each do |key, value|
(state_code = key) if (value.include? city_name)
end
state_code
end
puts find_state_for_city("Timbuktu")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment