Class: ANSIDataProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/people_places_things/data/process_data.rb

Overview

:nodoc:

Class Method Summary (collapse)

Class Method Details

+ (Object) run(in_filename, out_filename)



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/people_places_things/data/process_data.rb', line 6

def self.run(in_filename, out_filename)
  rownum = 0
  data = {}
  
  CSV::Reader.parse(File.open(in_filename, 'rb')) do |row|
    puts "processing row #{rownum}" if (rownum % 500) == 0
    
    if rownum > 0 && row.length == 5
      state = row[0].strip
      ansi = row[1].strip
      code = row[2].strip
      county = ANSICounties.normalize_county_name(row[3].strip)
      
      key = ANSICounties.key_for(state, county)
      value = "#{ansi.to_s}#{code.to_s}".to_i
      data[key] = value
    end
    
    rownum += 1
  end
  
  File.open(out_filename, 'wb') do |file|
    YAML.dump(data, file)
  end
end