class Madison::Map
Public Instance Methods
get_abbrev(name)
click to toggle source
# File lib/madison/map.rb, line 11 def get_abbrev(name) validate_arg(name) state_abbrevs[name.downcase] end
get_name(abbrev)
click to toggle source
# File lib/madison/map.rb, line 16 def get_name(abbrev) validate_arg(abbrev) state_names[abbrev.downcase] end
states()
click to toggle source
# File lib/madison/map.rb, line 5 def states lib_dir = File.expand_path(File.dirname(File.dirname(__FILE__))) @states ||= JSON.parse( File.open(File.join(lib_dir, "madison", "states.json")).read) end
Private Instance Methods
build_map(in_key, out_key)
click to toggle source
# File lib/madison/map.rb, line 31 def build_map(in_key, out_key) states.inject({}) do |map, state| map[state[in_key].downcase] = state[out_key] map end end
state_abbrevs()
click to toggle source
# File lib/madison/map.rb, line 27 def state_abbrevs @state_abbrevs ||= build_map('name', 'abbr') end
state_names()
click to toggle source
# File lib/madison/map.rb, line 23 def state_names @state_names ||= build_map('abbr', 'name') end
validate_arg(arg)
click to toggle source
# File lib/madison/map.rb, line 38 def validate_arg(arg) raise ArgumentError, "Argument '#{arg}' must be a string" unless arg.is_a? String end