Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit bb21d8087e443134a24dff2125a53a97d21ae502 1 parent 050f928
Codemis authored
View
4 lib/ofac_checker/doc_processor.rb
@@ -20,6 +20,7 @@ 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|
@@ -27,6 +28,7 @@ def process
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
@@ -34,7 +36,7 @@ def process
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
View
6 lib/ofac_checker/mailer.rb
@@ -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'],
View
4 spec/ofac_checker/mailer_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.