Class: Hyrax::CitationsBehaviors::Formatters::ChicagoFormatter

Inherits:
BaseFormatter
  • Object
show all
Includes:
PublicationBehavior, TitleBehavior
Defined in:
app/helpers/hyrax/citations_behaviors/formatters/chicago_formatter.rb

Constant Summary

Constants included from TitleBehavior

TitleBehavior::EXPANDED_NOCAPS, TitleBehavior::TITLE_NOCAPS

Instance Attribute Summary

Attributes inherited from BaseFormatter

#view_context

Instance Method Summary collapse

Methods included from TitleBehavior

#chicago_citation_title, #mla_citation_title, #process_title_parts, #setup_title_info

Methods included from CommonBehavior

#clean_end_punctuation, #persistent_url

Methods included from PublicationBehavior

#setup_pub_date, #setup_pub_info, #setup_pub_place, #setup_pub_publisher

Methods inherited from BaseFormatter

#initialize

Methods included from NameBehavior

#abbreviate_name, #all_authors, #author_list, #given_name_first, #surname_first

Constructor Details

This class inherits a constructor from Hyrax::CitationsBehaviors::Formatters::BaseFormatter

Instance Method Details

#format(work) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/helpers/hyrax/citations_behaviors/formatters/chicago_formatter.rb', line 8

def format(work)
  text = ""

  # setup formatted author list
  authors_list = all_authors(work)
  text += format_authors(authors_list)
  text = "<span class=\"citation-author\">#{text}</span>" if text.present?
  # Get Pub Date
  pub_date = setup_pub_date(work)
  text += " #{whitewash(pub_date)}." unless pub_date.nil?

  text += format_title(work.to_s)
  pub_info = setup_pub_info(work, false)
  text += " #{whitewash(pub_info)}." if pub_info.present?
  text.html_safe
end

#format_authors(authors_list = []) ⇒ Object



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

def format_authors(authors_list = [])
  return '' if authors_list.blank?
  text = ''
  text += surname_first(authors_list.first) if authors_list.first
  authors_list[1..6].each_with_index do |author, index|
    text += if index + 2 == authors_list.length # we've skipped the first author
              ", and #{given_name_first(author)}."
            else
              ", #{given_name_first(author)}"
            end
  end
  text += " et al." if authors_list.length > 7
  # if for some reason the first author ended with a comma
  text = text.gsub(',,', ',')
  text += "." unless text.end_with?(".")
  whitewash(text)
end

#format_date(pub_date) ⇒ Object



43
# File 'app/helpers/hyrax/citations_behaviors/formatters/chicago_formatter.rb', line 43

def format_date(pub_date); end

#format_title(title_info) ⇒ Object



45
46
47
48
49
50
51
# File 'app/helpers/hyrax/citations_behaviors/formatters/chicago_formatter.rb', line 45

def format_title(title_info)
  return "" if title_info.blank?
  title_text = chicago_citation_title(title_info)
  title_text += '.' unless title_text.end_with?(".")
  title_text = whitewash(title_text)
  " <i class=\"citation-title\">#{title_text}</i>"
end