Module: Identified::IssuingStateData

Defined in:
lib/identified/ssn/issuing_state_data.rb

Overview

Wraps the actual data file to provide convenient access to area number => issuing state info.

Constant Summary collapse

ISSUING_STATE_ENTRY_REGEX =
/(\d{3})-(\d{3})\s(\w{2})/

Class Method Summary collapse

Class Method Details

.issuing_states(area_number, date_issued) ⇒ Object

Provides an array of potential states or protectorates the ssn was issued in. Date is required because this information cannot be known if it was issued after the randomizaiton date. Unknown area numbers return [].



8
9
10
11
12
13
14
15
16
17
# File 'lib/identified/ssn/issuing_state_data.rb', line 8

def self.issuing_states(area_number, date_issued)
  # When the date issued is after the randomization date, we have no information about the
  # issuing area, so return [].
  return [] if !date_issued || date_issued >= SSN::RANDOMIZATION_DATE

  @issuing_areas_table ||= load_issuing_states_table

  # Return [] if the issuing areas information doesn't cover the requested area.
  @issuing_areas_table.fetch(area_number, [])
end

.load_issuing_states_tableObject

Loads the lookup table for going from area # => state / province code



20
21
22
23
24
25
26
27
# File 'lib/identified/ssn/issuing_state_data.rb', line 20

def self.load_issuing_states_table
  # Data originally taken from http://www.socialsecurity.gov/employer/stateweb.htm. The file
  # this reads was transformed slightly from the original to make it less cumbersome to parse.
  raw_data = File.read(File.join(Config.data_path, 'ssn/area_data.txt'))

  # issuing_states_table = parse_issuing_states(raw_data)
  parse_issuing_states(raw_data)
end

.parse_issuing_states(raw_data) ⇒ Object

Parses the issuing areas file contents and converts the data into a lookup table.



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/identified/ssn/issuing_state_data.rb', line 30

def self.parse_issuing_states(raw_data)
  lookup_table = {}

  # The data is formatted as a range [start]-[end] then the two character state / province code.
  raw_data.scan(ISSUING_STATE_ENTRY_REGEX) do |start_area, end_area, state_code|
    (start_area.to_i).upto(end_area.to_i) do |area_number|
      lookup_table[area_number] ||= []
      lookup_table.fetch(area_number) << state_code
    end
  end

  lookup_table
end