class AnnotationFormComponent < BaseComponent attr_reader :annotation, :opts def initialize(current_user:, annotation:, opts: {}) @annotation = annotation @opts = opts end def document return annotation.document if annotation.persisted? Cdao::Document.find(opts[:document_id].to_i) end def clean_phil_rep(annotation) return if annotation.phil_rep.blank? annotation.phil_rep.gsub(/(PhilRep|Phil)\.?,?/i, "Phil") end def display_text return annotation.content if annotation.persisted? && annotation.content.present? && annotation.content.include?("Phil") display_text = nil title = document.short_title || document.title year_or_date = document.doc_date.present? ? document.doc_date.strftime("%B %d, %Y") : document.year if annotation.new_record? display_text = [title, document.clean_reference_number, year_or_date].join(", ") else contents = [[title, document.clean_reference_number, year_or_date].reject(&:blank?).join(", ")] annotation.documents.each do |citing_doc| citing_doc_title = citing_doc.short_title || citing_doc.title citing_doc_year_or_date = citing_doc.doc_date.present? ? citing_doc.doc_date.strftime("%B %d, %Y") : citing_doc.year contents << [citing_doc_title, citing_doc.clean_reference_number, citing_doc_year_or_date].join(", ") end display_text = contents.reject(&:blank?).join(" citing ") end display_text end def phil_rep return annotation.phil_rep if annotation.persisted? document.phil_rep end end