Sha256: 09e7fc8e523f48d29d3ddf05af7e8dacc6321f7ac063992bc8310c9e14dc3b8f

Contents?: true

Size: 1.09 KB

Versions: 4

Compression:

Stored size: 1.09 KB

Contents

# encoding: UTF-8
module Geolookup
  module USA
    module Metro
      METRO_CODE_TO_NAME_FILE = 'METRO_CODE_TO_NAME.yml'

      @metro_code_to_name

      ###################################################################
      # self.code_to_name
      #
      # Given a metro code output the metro name
      # Else return nil
      #
      # EX: code_to_name(4) => "Abilene"
      def self.code_to_name(metro_code)
        @metro_code_to_name ||= Geolookup.load_hash_from_file(METRO_CODE_TO_NAME_FILE)
        get_value_from_hash(@metro_code_to_name, metro_code.to_s.to_i)
      end

      ###################################################################
      # self.get_value_from_hash
      #
      # Helper function to reduce code repetition
      # Given a hash and 1 key returns the value at that hash
      # Return nil if the either key is not in the hash
      #
      # EX: get_value(@metro_code_to_name, 4) => "Abilene"
      def self.get_value_from_hash(hash, key1)
        return nil unless hash[key1]
        hash[key1]
      end

      private_class_method :get_value_from_hash
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
geolookup-0.6.4 lib/geolookup/usa/metro.rb
geolookup-0.6.2 lib/geolookup/usa/metro.rb
geolookup-0.6.1 lib/geolookup/usa/metro.rb
geolookup-0.6.0 lib/geolookup/usa/metro.rb