Sha256: 125cddbc101769813274120afa473d219d1f154ff5b5790e7a722ef6fbe31c49

Contents?: true

Size: 1.49 KB

Versions: 26

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true
module Hyrax
  module CitationsBehaviors
    module TitleBehavior
      include Hyrax::CitationsBehaviors::CommonBehavior

      TITLE_NOCAPS = ["a", "an", "and", "but", "by", "for", "it", "of", "the", "to", "with"].freeze
      EXPANDED_NOCAPS = TITLE_NOCAPS + ["about", "across", "before", "without"]

      def chicago_citation_title(title_text)
        process_title_parts(title_text) do |w, index|
          if (index.zero? && w.casecmp(w).zero?) || (w.length > 1 && w.casecmp(w).zero? && !EXPANDED_NOCAPS.include?(w))
            # the split("-") will handle the capitalization of hyphenated words
            w.split("-").map!(&:capitalize).join("-")
          else
            w
          end
        end
      end

      def mla_citation_title(title_text)
        process_title_parts(title_text) do |w|
          if TITLE_NOCAPS.include? w
            w
          else
            w.capitalize
          end
        end
      end

      def process_title_parts(title_text, &block)
        if block_given?
          title_text.split(" ").collect.with_index(&block).join(" ")
        else
          title_text
        end
      end

      def setup_title_info(work)
        text = ''
        title = work.to_s
        if title.present?
          title = CGI.escapeHTML(title)
          title_info = clean_end_punctuation(title.strip)
          text += title_info
        end

        return nil if text.strip.blank?
        clean_end_punctuation(text.strip) + "."
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
hyrax-5.0.2 app/helpers/hyrax/citations_behaviors/title_behavior.rb
hyrax-5.0.1 app/helpers/hyrax/citations_behaviors/title_behavior.rb
hyrax-5.0.0 app/helpers/hyrax/citations_behaviors/title_behavior.rb
hyrax-5.0.0.rc3 app/helpers/hyrax/citations_behaviors/title_behavior.rb
hyrax-5.0.0.rc2 app/helpers/hyrax/citations_behaviors/title_behavior.rb
hyrax-5.0.0.rc1 app/helpers/hyrax/citations_behaviors/title_behavior.rb
hyrax-3.6.0 app/helpers/hyrax/citations_behaviors/title_behavior.rb
hyrax-4.0.0 app/helpers/hyrax/citations_behaviors/title_behavior.rb
hyrax-4.0.0.rc3 app/helpers/hyrax/citations_behaviors/title_behavior.rb
hyrax-4.0.0.rc2 app/helpers/hyrax/citations_behaviors/title_behavior.rb
hyrax-4.0.0.rc1 app/helpers/hyrax/citations_behaviors/title_behavior.rb
hyrax-3.5.0 app/helpers/hyrax/citations_behaviors/title_behavior.rb
hyrax-4.0.0.beta2 app/helpers/hyrax/citations_behaviors/title_behavior.rb
hyrax-3.4.2 app/helpers/hyrax/citations_behaviors/title_behavior.rb
hyrax-4.0.0.beta1 app/helpers/hyrax/citations_behaviors/title_behavior.rb
hyrax-3.4.1 app/helpers/hyrax/citations_behaviors/title_behavior.rb
hyrax-3.4.0 app/helpers/hyrax/citations_behaviors/title_behavior.rb
hyrax-3.3.0 app/helpers/hyrax/citations_behaviors/title_behavior.rb
hyrax-3.2.0 app/helpers/hyrax/citations_behaviors/title_behavior.rb
hyrax-3.1.0 app/helpers/hyrax/citations_behaviors/title_behavior.rb