Created
March 8, 2011 16:21
-
-
Save knewter/860480 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
module ProgramManagerBatchInterface | |
module Models | |
# Used to build the CSV files that are sent to the Program Manager to request | |
# Account Information on a given subset of their account base. | |
# | |
# Files look like the following: | |
# pseudo_dda, updated_at, status | |
# 12345, 2011-01-01 00:00:00, applicant | |
# | |
# To use: | |
# f = AccountInformationRequestFile.new | |
# f << { :pseudo_dda => '12345', :updated_at => Time.parse('2011-01-01 00:00:00'), :status => 'applicant' } | |
# f.generate_file # outputs guid, writes file at File.join(ProgramManagerBatchInterface.local_base_dir, 'account_information_request_files', "#{guid}.csv" | |
# | |
# f.path # outputs path to file | |
# f.guid # guid set at initialization | |
class AccountInformationRequestFile | |
extend Forwardable | |
attr_accessor :guid, :rows | |
def_delegators :rows, :<< | |
def initialize | |
self.guid = UUIDTools::UUID.random_create.hexdigest | |
self.rows = [] | |
end | |
def base_directory | |
File.join(ProgramManagerBatchInterface.local_base_dir, 'account_information_request_files') | |
end | |
def path | |
File.join(base_directory, "#{guid}.csv") | |
end | |
def headers | |
['pseudo_dda', 'updated_at', 'status'] | |
end | |
def ensure_directory | |
unless File.directory?(base_directory) | |
FileUtils.mkdir_p(base_directory) | |
end | |
end | |
def generate_file | |
ensure_directory | |
CSV.open(path, 'wb') do |csv| | |
csv << headers | |
rows.each do |r| | |
csv << [r[:pseudo_dda], r[:updated_at], r[:status]] | |
end | |
end | |
guid | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment