Created
April 1, 2013 05:47
-
-
Save supernullset/5283424 to your computer and use it in GitHub Desktop.
First pass aggregator
This file contains 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
class Aggregator | |
def initialize(target_filename, output_filename, pattern, output_file_type=nil) | |
@target_filename = target_filename | |
@output_filename = output_filename | |
@pattern = pattern | |
@output_file_type = output_file_type || "csv" | |
end | |
def run | |
open_files | |
parse_files | |
close_files | |
end | |
private | |
def open_files | |
@target = File.open(@target_filename, "r") | |
@output = File.open(@output_filename, "r+") | |
end | |
def close_files | |
@target.close | |
@output.close | |
end | |
def parse_files | |
@target.each do |line| | |
if line =~ @pattern | |
@output.puts line | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment