Browse Source

Add `callback` for `annotation`

pull/122/head
alexdbondoc17 4 years ago
parent
commit
74a094aae8
  1. 14
      app/models/annotation.rb

14
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
@ -31,6 +33,18 @@ class Annotation < ApplicationRecord
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
integer :doctrine_id

Loading…
Cancel
Save