Class: Hyrax::CitationsBehaviors::Formatters::ApaFormatter

Inherits:
BaseFormatter
  • Object
show all
Includes:
PublicationBehavior, TitleBehavior
Defined in:
app/helpers/hyrax/citations_behaviors/formatters/apa_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



9
10
11
12
13
14
15
16
# File 'app/helpers/hyrax/citations_behaviors/formatters/apa_formatter.rb', line 9

def format(work)
  text = ''
  text += authors_text_for(work)
  text += pub_date_text_for(work)
  text += add_title_text_for(work)
  text += add_publisher_text_for(work)
  text.html_safe
end

#format_authors(authors_list = []) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/helpers/hyrax/citations_behaviors/formatters/apa_formatter.rb', line 33

def format_authors(authors_list = [])
  return '' if authors_list.blank?
  authors_list = Array.wrap(authors_list).collect { |name| abbreviate_name(surname_first(name)).strip }
  text = ''
  text += authors_list.first if authors_list.first
  authors_list[1..-1].each do |author|
    text += if author == authors_list.last # last
              ", & #{author}"
            else # all others
              ", #{author}"
            end
  end
  text += "." unless text.end_with?(".")
  text
end

#format_date(pub_date) ⇒ Object



75
76
77
# File 'app/helpers/hyrax/citations_behaviors/formatters/apa_formatter.rb', line 75

def format_date(pub_date)
  pub_date.blank? ? "" : "(" + pub_date + "). "
end

#format_title(title_info) ⇒ Object



79
80
81
# File 'app/helpers/hyrax/citations_behaviors/formatters/apa_formatter.rb', line 79

def format_title(title_info)
  title_info.nil? ? "" : "<i class=\"citation-title\">#{title_info}</i> "
end