You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.8 KiB
71 lines
1.8 KiB
class Annotation < ApplicationRecord |
|
acts_as_list column: :rank, scope: %i[doctrine_id] |
|
|
|
belongs_to :doctrine, optional: false |
|
|
|
belongs_to :document, polymorphic: true, optional: false |
|
|
|
has_many :annotation_documents, inverse_of: :annotation, dependent: :destroy |
|
accepts_nested_attributes_for :annotation_documents, allow_destroy: true |
|
|
|
has_many :annotation_annomarks, dependent: :destroy |
|
has_many :annomarks, through: :annotation_annomarks |
|
|
|
validates :content, presence: true |
|
|
|
before_save :parse_content |
|
|
|
def documents |
|
annotation_documents.collect(&:document) |
|
end |
|
|
|
def add_document(document) |
|
record = annotation_documents.new |
|
record.document = document |
|
record.save |
|
end |
|
|
|
def remove_document(document) |
|
annotation_documents.find_by(document_id: document.id).destroy |
|
end |
|
|
|
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 |
|
integer :doctrine_id |
|
|
|
integer :library_rank do |
|
document.library.rank |
|
end |
|
|
|
integer :search_year do |
|
document.year.present? && document.year > 0 ? document.year : (document.doc_date.try :year) |
|
end |
|
|
|
date :search_doc_date do |
|
document.doc_date.presence || Date.new(year.presence || 0) |
|
end |
|
|
|
date :created_at |
|
date :updated_at |
|
|
|
text :phil_rep |
|
|
|
string :phil_rep |
|
end |
|
end
|
|
|