module SunDawg::USAStateTranslater

Constants

FILE

allows client application to override YAML hash

USA_STATES

Public Class Methods

translate_code_to_name(code) click to toggle source

O(1) translation of 2-digit code to name

# File lib/usa_state_translater.rb, line 18
def self.translate_code_to_name(code)
  state = USA_STATES[code]
  raise NoStateError.new("[#{code}] IS NOT VALID") if state.nil?
  state["name"]
end
translate_name_to_code(name) click to toggle source

O(N) translation from state name to 2-digit code

# File lib/usa_state_translater.rb, line 10
def self.translate_name_to_code(name)
  USA_STATES.each_pair do |key, value| 
    return key if value["name"] == name 
  end
  raise NoStateError.new("[#{name}] IS NOT VALID")
end