Sha256: 4a8c6eb596d4e7349b02906bbb1361d1132b61e9b7de22476f0cbdcbec9ad342

Contents?: true

Size: 1.46 KB

Versions: 48

Compression:

Stored size: 1.46 KB

Contents

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

48 entries across 48 versions & 1 rubygems

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