Module: SunDawg::USAStateTranslater
- Defined in:
- lib/usa_state_translater.rb
Defined Under Namespace
Classes: NoStateError
Constant Summary collapse
- FILE =
allows client application to override YAML hash
File.(File.join(File.dirname(__FILE__), 'usa_states.yml'))
- USA_STATES =
YAML.load_file(FILE)
Class Method Summary collapse
-
.translate_code_to_name(code) ⇒ Object
O(1) translation of 2-digit code to name.
-
.translate_name_to_code(name) ⇒ Object
O(N) translation from state name to 2-digit code.
Class Method Details
.translate_code_to_name(code) ⇒ Object
O(1) translation of 2-digit code to name
18 19 20 21 22 |
# 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) ⇒ Object
O(N) translation from state name to 2-digit code
10 11 12 13 14 15 |
# 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 |