Skip to content

Commit

Permalink
Added report links to paperworks #42
Browse files Browse the repository at this point in the history
  • Loading branch information
maugsbur committed Feb 27, 2014
1 parent 97df0af commit ce2c167
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion app/models/paperwork.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ce2c167

Please sign in to comment.