diff --git a/app/models/annotation.rb b/app/models/annotation.rb index acf06cb..d067d9d 100644 --- a/app/models/annotation.rb +++ b/app/models/annotation.rb @@ -13,6 +13,8 @@ class Annotation < ApplicationRecord validates :content, presence: true + before_save :parse_content + def documents annotation_documents.collect(&:document) end @@ -30,6 +32,18 @@ class Annotation < ApplicationRecord def citing_document_ids documents.map(&:id) end + + + def parse_content + pr = phil_rep.gsub(/(PhilRep|Phil)\.?,?/i, "Phil") + pr = pr.gsub(/(PhilRep|Phil)\.?,?/i, "Phil") + annotated_doc_title = document.short_title || document.title + annotated_doc_date = document.doc_date.present? ? document.doc_date.try(:strftime, "%B %d, %Y") : document.year + contents = content.split(" citing ") + contents[0] = [annotated_doc_title, document.clean_reference_number, annotated_doc_date, pr].join(", ") + + self.content = contents.join(" citing ") + end searchable do integer :document_id