dburkes-people_places_things 1.1.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,33 @@
1
+ require 'csv'
2
+ require 'yaml'
3
+ require '../../ansi-counties'
4
+
5
+ class ANSIDataProcessor #:nodoc:
6
+ def self.run(in_filename, out_filename)
7
+ rownum = 0
8
+ data = {}
9
+
10
+ CSV::Reader.parse(File.open(in_filename, 'rb')) do |row|
11
+ puts "processing row #{rownum}" if (rownum % 500) == 0
12
+
13
+ if rownum > 0 && row.length == 5
14
+ state = row[0].strip
15
+ ansi = row[1].strip
16
+ code = row[2].strip
17
+ county = ANSICounties.normalize_county_name(row[3].strip)
18
+
19
+ key = ANSICounties.key_for(state, county)
20
+ value = "#{ansi.to_s}#{code.to_s}".to_i
21
+ data[key] = value
22
+ end
23
+
24
+ rownum += 1
25
+ end
26
+
27
+ File.open(out_filename, 'wb') do |file|
28
+ YAML.dump(data, file)
29
+ end
30
+ end
31
+ end
32
+
33
+ ANSIDataProcessor.run(ARGV[0], ARGV[1])