Browse Source

Add `doctrine#plain_content`

pull/23/head
Angel Aviel Domaoan 4 years ago committed by Angel Aviel Domaoan
parent
commit
c48fe7321d
  1. 2
      Gemfile
  2. 4
      Gemfile.lock
  3. 8
      app/models/cdao/citation_finder.rb
  4. 47
      app/models/cdao/jurisprudence.rb
  5. 4
      app/models/doctrine.rb
  6. 2
      app/views/api/doctrines/index.json.jbuilder
  7. 2
      app/views/api/doctrines/show.json.jbuilder

2
Gemfile

@ -122,3 +122,5 @@ group :development do
end
gem "faker", "~> 2.19"
gem "sanitize", "~> 6.0"

4
Gemfile.lock

@ -305,6 +305,9 @@ GEM
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
sanitize (6.0.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
sass-rails (6.0.0)
sassc-rails (~> 2.1, >= 2.1.1)
sassc (2.4.0)
@ -457,6 +460,7 @@ DEPENDENCIES
rubocop-packaging
rubocop-performance
rubocop-rails
sanitize (~> 6.0)
sass-rails (>= 6)
secure_headers (>= 6.3.0)
selenium-webdriver

8
app/models/cdao/citation_finder.rb

@ -0,0 +1,8 @@
class Cdao::CitationFinder < Cdao::Base
self.table_name = "citation_finders"
TYPES = %w[SCRA PhilRep].freeze
belongs_to :jurisprudence, class_name: "Cdao::Jurisprudence", optional: false
delegate :title, :content, :ponente, :syllabus, :reference_number, :docdate, to: :jurisprudence
end

47
app/models/cdao/jurisprudence.rb

@ -8,6 +8,8 @@ class Cdao::Jurisprudence < Cdao::Base
has_many :annotation_documents, as: :document, dependent: :restrict_with_error
has_many :annotations_as_cited, through: :annotation_documents, source: :annotation
has_many :citation_finders, dependent: :restrict_with_error
alias_attribute :doc_date, :docdate
def cited_documents
@ -99,4 +101,49 @@ class Cdao::Jurisprudence < Cdao::Base
join(:phil_rep, :target => Annotation, :type => :string, :join => { :from => :document_id, :to => :id })
end
def phil_rep
names = citation_finders_names.keep_if { |a| a.match?("Phil") }
end
def scra
names = citation_finders_names.keep_if { |a| a.match?(Cdao::CitationFinder::TYPES[0]) }
names
end
def citation_finders_names
return [] if citation_finders.blank?
names = []
citation_finders.each do |citation_finder|
volumes = citation_finder.volume.gsub(/\s+/, "").gsub(/\A0*/, "") if citation_finder.volume.present?
pages = if citation_finder.first_page.present? && citation_finder.last_page.present?
(citation_finder.first_page..citation_finder.last_page).to_a
elsif citation_finder.first_page.present?
[citation_finder.first_page]
elsif citation_finder.last_page.present?
[citation_finder.last_page]
else
[]
end
types = if citation_finder.citation_source_id.present?
citation_finder.citation_source_id == 0 ? ["SCRA"] : ["Phil"]
else
[]
end
types.each do |type|
names << ("#{volumes.presence} #{type}").strip
pages.each do |page|
names << ("#{volumes.presence} #{type} #{page}").strip
end
end
end
names
end
end

4
app/models/doctrine.rb

@ -43,6 +43,10 @@ class Doctrine < ApplicationRecord
subject_ids
end
def plain_content
Sanitize.clean(content).strip
end
searchable do
text :content

2
app/views/api/doctrines/index.json.jbuilder

@ -1,3 +1,3 @@
json.array!(@doctrines) do |doctrine|
json.extract! doctrine, *%i[id content subject_ids created_at updated_at]
json.extract! doctrine, *%i[id subject_ids content plain_content created_at updated_at]
end

2
app/views/api/doctrines/show.json.jbuilder

@ -1 +1 @@
json.(@doctrine, *%i[id content subject_ids created_at updated_at])
json.(@doctrine, *%i[id subject_ids content plain_content created_at updated_at])

Loading…
Cancel
Save