Module: Hyrax::CitationsBehaviors::PublicationBehavior

Includes:
CommonBehavior
Included in:
Hyrax::CitationsBehavior, Formatters::ApaFormatter, Formatters::ChicagoFormatter, Formatters::MlaFormatter
Defined in:
app/helpers/hyrax/citations_behaviors/publication_behavior.rb

Instance Method Summary collapse

Methods included from CommonBehavior

#clean_end_punctuation, #persistent_url

Instance Method Details

#setup_pub_date(work) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'app/helpers/hyrax/citations_behaviors/publication_behavior.rb', line 6

def setup_pub_date(work)
  first_date = work.date_created.first if work.date_created
  if first_date.present?
    first_date = CGI.escapeHTML(first_date)
    date_value = first_date.gsub(/[^0-9|n\.d\.]/, "")[0, 4]
    return nil if date_value.nil?
  end
  clean_end_punctuation(date_value) if date_value
end

#setup_pub_info(work, include_date = false) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/helpers/hyrax/citations_behaviors/publication_behavior.rb', line 25

def setup_pub_info(work, include_date = false)
  pub_info = ""
  if (place = setup_pub_place(work))
    pub_info += CGI.escapeHTML(place)
  end
  if (publisher = setup_pub_publisher(work))
    pub_info += ": #{CGI.escapeHTML(publisher)}"
  end

  pub_date = include_date ? setup_pub_date(work) : nil
  pub_info += ", #{pub_date}" unless pub_date.nil?

  pub_info.strip.presence
end

#setup_pub_place(work_presenter) ⇒ Object

Parameters:



17
18
19
# File 'app/helpers/hyrax/citations_behaviors/publication_behavior.rb', line 17

def setup_pub_place(work_presenter)
  work_presenter.based_near_label&.first
end

#setup_pub_publisher(work) ⇒ Object



21
22
23
# File 'app/helpers/hyrax/citations_behaviors/publication_behavior.rb', line 21

def setup_pub_publisher(work)
  work.publisher&.first
end