Permalink
Browse files

Added a hit count to eliminate a need to look at results file.

  • Loading branch information...
1 parent 050f928 commit bb21d8087e443134a24dff2125a53a97d21ae502 Codemis committed Mar 20, 2012
Showing with 7 additions and 7 deletions.
  1. +3 −1 lib/ofac_checker/doc_processor.rb
  2. +3 −3 lib/ofac_checker/mailer.rb
  3. +1 −3 spec/ofac_checker/mailer_spec.rb
@@ -20,21 +20,23 @@ def initialize(doc, result_location, settings)
# process the document
#
def process
+ hits = 0
CSV.open("#{@result_file}", "w") do |csv|
csv << ['Payee','Score', 'Possible Result','Address']
payees.each do |payee|
ofac = Ofac.new({:name => "#{payee}"})
if ofac.possible_hits.empty?
csv << ["#{payee}","#{ofac.score}", '','']
else
+ hits = hits+1
ofac.possible_hits.each do |potential|
csv << ["#{payee}","#{ofac.score}", "#{potential[:name]}","#{potential[:address]} - #{potential[:city]}"]
end
end # if possible hits
end # each payee
end # CSV
cleanup
- @mailer.task_complete(@email_settings, @result_file)
+ @mailer.task_complete(@email_settings, @result_file, hits)
end
# cleanup the process
@@ -4,13 +4,13 @@ class Mailer
# 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
from 'no-reply@localhost.com'
to settings['to']
- subject settings['subject']
+ subject "#{settings['subject']} - #{hits} Hits"
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
Mail.defaults do
retriever_method :pop3, :address => settings['address'],
@@ -3,7 +3,7 @@
before(:each) do
Mail::TestMailer.deliveries.clear
@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
it "should send the user an email" do
@@ -12,6 +12,4 @@
it { should have_sent_email.to(SETTINGS['email_smtp']['to']) }
- it { should have_sent_email.with_subject(SETTINGS['email_smtp']['subject']) }
-
end

0 comments on commit bb21d80

Please sign in to comment.