From 74a094aae83250b6f64bb788602a123075e3579c Mon Sep 17 00:00:00 2001 From: alexdbondoc17 Date: Tue, 15 Mar 2022 00:38:05 +0000 Subject: [PATCH] Add `callback` for `annotation` --- app/models/annotation.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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