Sha256: a314647d339096d0d2097f413575da3f107543f74a199f6625502a5404a8bc91

Contents?: true

Size: 1.83 KB

Versions: 52

Compression:

Stored size: 1.83 KB

Contents

module Hyrax
  module CitationsBehaviors
    module Formatters
      class MlaFormatter < BaseFormatter
        include Hyrax::CitationsBehaviors::PublicationBehavior
        include Hyrax::CitationsBehaviors::TitleBehavior

        def format(work)
          text = ''

          # setup formatted author list
          authors = author_list(work).reject(&:blank?)
          text << "<span class=\"citation-author\">#{format_authors(authors)}</span>"
          # setup title
          title_info = setup_title_info(work)
          text << format_title(title_info)

          # Publication
          pub_info = clean_end_punctuation(setup_pub_info(work, true))

          text << pub_info + "." if pub_info.present?
          text.html_safe
        end

        def format_authors(authors_list = [])
          return "" if authors_list.blank?
          authors_list = Array.wrap(authors_list)
          text = concatenate_authors_from(authors_list)
          if text.present?
            text << "." unless text =~ /\.$/
            text << " "
          end
          text
        end

        def concatenate_authors_from(authors_list)
          text = ''
          text << surname_first(authors_list.first)
          if authors_list.length > 1
            if authors_list.length < 4
              authors_list[1...-1].each do |author|
                text << ", " << given_name_first(author)
              end
              text << ", and #{given_name_first(authors_list.last)}"
            else
              text << ", et al"
            end
          end
          text
        end
        private :concatenate_authors_from

        def format_date(pub_date)
          pub_date
        end

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

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
hyrax-2.9.6 app/helpers/hyrax/citations_behaviors/formatters/mla_formatter.rb
hyrax-2.9.5 app/helpers/hyrax/citations_behaviors/formatters/mla_formatter.rb
hyrax-2.9.4 app/helpers/hyrax/citations_behaviors/formatters/mla_formatter.rb
hyrax-2.9.3 app/helpers/hyrax/citations_behaviors/formatters/mla_formatter.rb
hyrax-2.9.2 app/helpers/hyrax/citations_behaviors/formatters/mla_formatter.rb
hyrax-2.9.1 app/helpers/hyrax/citations_behaviors/formatters/mla_formatter.rb
hyrax-2.9.0 app/helpers/hyrax/citations_behaviors/formatters/mla_formatter.rb
hyrax-2.8.0 app/helpers/hyrax/citations_behaviors/formatters/mla_formatter.rb
hyrax-2.7.2 app/helpers/hyrax/citations_behaviors/formatters/mla_formatter.rb
hyrax-2.7.1 app/helpers/hyrax/citations_behaviors/formatters/mla_formatter.rb
hyrax-2.7.0 app/helpers/hyrax/citations_behaviors/formatters/mla_formatter.rb
hyrax-2.6.0 app/helpers/hyrax/citations_behaviors/formatters/mla_formatter.rb
hyrax-3.0.0.pre.rc1 app/helpers/hyrax/citations_behaviors/formatters/mla_formatter.rb
hyrax-3.0.0.pre.beta3 app/helpers/hyrax/citations_behaviors/formatters/mla_formatter.rb
hyrax-2.5.1 app/helpers/hyrax/citations_behaviors/formatters/mla_formatter.rb
hyrax-2.5.0 app/helpers/hyrax/citations_behaviors/formatters/mla_formatter.rb
hyrax-3.0.0.pre.beta2 app/helpers/hyrax/citations_behaviors/formatters/mla_formatter.rb
hyrax-2.4.1 app/helpers/hyrax/citations_behaviors/formatters/mla_formatter.rb
hyrax-3.0.0.pre.beta1 app/helpers/hyrax/citations_behaviors/formatters/mla_formatter.rb
hyrax-2.4.0 app/helpers/hyrax/citations_behaviors/formatters/mla_formatter.rb