-
-
Save macdiva/613973 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'yajl/json_gem' | |
module AP | |
# a = AP::ParseData.new('/file.txt') | |
class ParseData | |
def initialize(file) | |
@file = file | |
@ap_scratch = [] | |
@final_results = [] | |
end | |
#a.parse | |
def parse | |
@ap_scratch = File.new(@file).readlines | |
@ap_scratch[7..68].each do |line| | |
h = {} | |
results = line.gsub(/[\000-\037]/,' ').gsub(/,/,'').scan(/(\w+)/) | |
h[:county] = results[0][0] | |
h[:precincts_total] = results[1][0] | |
h[:precincts_reporting] = results[2][0] | |
h[:cuomo] = results[3][0] | |
h[:paladino] = results[4][0] | |
h[:lazio] = results[5][0] | |
h[:schaeffer] = results[6][0] | |
@final_results << h | |
end | |
json_file = File.new('ny.json','w+') | |
json_file.write(@final_results.to_json) | |
json_file.close | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment