From ce2c16786a16c3d0f0584d05663dee20dfca44f3 Mon Sep 17 00:00:00 2001 From: Marcel Augsburger Date: Thu, 27 Feb 2014 18:22:07 -0300 Subject: [PATCH] Added report links to paperworks #42 --- app/models/paperwork.rb | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/app/models/paperwork.rb b/app/models/paperwork.rb index 0065170..595b0d9 100644 --- a/app/models/paperwork.rb +++ b/app/models/paperwork.rb @@ -5,7 +5,7 @@ class Paperwork belongs_to :bill - before_save :save_bill_uid, :index_paperwork, :define_timeline_status, :set_document_link + before_save :save_bill_uid, :index_paperwork, :define_timeline_status, :set_external_links field :session, :type => String field :date, :type => DateTime @@ -72,6 +72,33 @@ def set_document_link end end + def set_report_link + reports = Bill.find(self.bill_id).reports + reports.each do |report| + stage_match = (clean_string report.stage) == (clean_string self.stage) + description_match = (clean_string report.step) == (clean_string self.description) + if report.date == self.date && stage_match && description_match + self.report_link = report.link + end + end + end + + def set_external_links + set_model_link 'report' + set_model_link 'document' + end + + def set_model_link model + model_values = Bill.find(self.bill_id).send model.pluralize + model_values.each do |model_value| + stage_match = (clean_string model_value.stage) == (clean_string self.stage) + description_match = (clean_string model_value.step) == (clean_string self.description) + if model_value.date == self.date && stage_match && description_match + self.send(model.singularize + '_link=', model_value.link) + end + end + end + def clean_string messy_string clean_string = messy_string.strip.chomp('.').strip clean_string = I18n.transliterate(clean_string, locale: :transliterate_special).downcase