Skip to content
This repository has been archived by the owner on Sep 18, 2019. It is now read-only.

Commit

Permalink
Added a hit count to eliminate a need to look at results file.
Browse files Browse the repository at this point in the history
  • Loading branch information
Codemis committed Mar 20, 2012
1 parent 050f928 commit bb21d80
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 3 additions & 1 deletion lib/ofac_checker/doc_processor.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,21 +20,23 @@ def initialize(doc, result_location, settings)
# process the document # process the document
# #
def process def process
hits = 0
CSV.open("#{@result_file}", "w") do |csv| CSV.open("#{@result_file}", "w") do |csv|
csv << ['Payee','Score', 'Possible Result','Address'] csv << ['Payee','Score', 'Possible Result','Address']
payees.each do |payee| payees.each do |payee|
ofac = Ofac.new({:name => "#{payee}"}) ofac = Ofac.new({:name => "#{payee}"})
if ofac.possible_hits.empty? if ofac.possible_hits.empty?
csv << ["#{payee}","#{ofac.score}", '',''] csv << ["#{payee}","#{ofac.score}", '','']
else else
hits = hits+1
ofac.possible_hits.each do |potential| ofac.possible_hits.each do |potential|
csv << ["#{payee}","#{ofac.score}", "#{potential[:name]}","#{potential[:address]} - #{potential[:city]}"] csv << ["#{payee}","#{ofac.score}", "#{potential[:name]}","#{potential[:address]} - #{potential[:city]}"]
end end
end # if possible hits end # if possible hits
end # each payee end # each payee
end # CSV end # CSV
cleanup cleanup
@mailer.task_complete(@email_settings, @result_file) @mailer.task_complete(@email_settings, @result_file, hits)
end end


# cleanup the process # cleanup the process
Expand Down
6 changes: 3 additions & 3 deletions lib/ofac_checker/mailer.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ class Mailer


# Send the task complete email. Make sure to .deliver it # Send the task complete email. Make sure to .deliver it
# #
def task_complete(settings, completed_file) def task_complete(settings, completed_file, hits)
mail = Mail.new do mail = Mail.new do
from 'no-reply@localhost.com' from 'no-reply@localhost.com'
to settings['to'] to settings['to']
subject settings['subject'] subject "#{settings['subject']} - #{hits} Hits"
body File.read(File.join(File.dirname(__FILE__), 'mail_templates', 'task_complete.txt')) body File.read(File.join(File.dirname(__FILE__), 'mail_templates', 'task_complete.txt'))
add_file :filename => 'results.csv', :content => File.read(completed_file) add_file :filename => 'results.csv', :content => File.read(completed_file) if hits != 0
end end
Mail.defaults do Mail.defaults do
retriever_method :pop3, :address => settings['address'], retriever_method :pop3, :address => settings['address'],
Expand Down
4 changes: 1 addition & 3 deletions spec/ofac_checker/mailer_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
before(:each) do before(:each) do
Mail::TestMailer.deliveries.clear Mail::TestMailer.deliveries.clear
@mailer = Mailer.new @mailer = Mailer.new
@mailer.task_complete(SETTINGS['email_smtp'], File.join(File.expand_path(File.join('../../'), __FILE__), "files", "attachments", "test.csv")) @mailer.task_complete(SETTINGS['email_smtp'], File.join(File.expand_path(File.join('../../'), __FILE__), "files", "attachments", "test.csv"), 10)
end end


it "should send the user an email" do it "should send the user an email" do
Expand All @@ -12,6 +12,4 @@


it { should have_sent_email.to(SETTINGS['email_smtp']['to']) } it { should have_sent_email.to(SETTINGS['email_smtp']['to']) }


it { should have_sent_email.with_subject(SETTINGS['email_smtp']['subject']) }

end end

0 comments on commit bb21d80

Please sign in to comment.