Method: Sufia::CitationsBehaviors::Formatters::ChicagoFormatter#format_authors

Defined in:
app/helpers/sufia/citations_behaviors/formatters/chicago_formatter.rb

#format_authors(authors_list = []) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/helpers/sufia/citations_behaviors/formatters/chicago_formatter.rb', line 28

def format_authors(authors_list = [])
  unless 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
  end
  # if for some reason the first author ended with a comma
  text.gsub!(',,', ',')
  text << "." unless text =~ /\.$/
  text
end