Sha256: 8d18a4b46f6f0297f93798392569f9fe4eeba330f834c9bbe0f83098857e9b87
Contents?: true
Size: 750 Bytes
Versions: 1
Compression:
Stored size: 750 Bytes
Contents
require 'yaml' require 'singleton' class ZipCodeInfo include Singleton attr_reader :code def initialize @data = YAML.load(File.open(File.join(File.dirname(__FILE__), '..', 'data', 'data.yml'))) end def scf_city_for(code = "") return false unless assign_and_validate_code(code) @data[code_to_key][:city] end def state_for(code = "") return false unless assign_and_validate_code(code) @data[code_to_key][:state] end private def assign_and_validate_code(code) @code = code.to_s return @code.match(/^[0-9]{5}$/i) && @data.has_key?(code_to_key) end # To look up information we only need the first three digits of the zip code def code_to_key @code[0..2] end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
zip-code-info-0.1.1 | lib/zip-code-info.rb |