Skip to content

Instantly share code, notes, and snippets.

@supernullset
Created April 1, 2013 05:47
Show Gist options
  • Save supernullset/5283424 to your computer and use it in GitHub Desktop.
Save supernullset/5283424 to your computer and use it in GitHub Desktop.
First pass aggregator
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