Module: Hyrax::CitationsBehaviors::TitleBehavior

Includes:
CommonBehavior
Included in:
Hyrax::CitationsBehavior, Formatters::ApaFormatter, Formatters::ChicagoFormatter, Formatters::MlaFormatter
Defined in:
app/helpers/hyrax/citations_behaviors/title_behavior.rb

Constant Summary collapse

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

Instance Method Summary collapse

Methods included from CommonBehavior

#clean_end_punctuation, #persistent_url

Instance Method Details

#chicago_citation_title(title_text) ⇒ Object


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

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

#mla_citation_title(title_text) ⇒ Object


20
21
22
23
24
25
26
27
28
# File 'app/helpers/hyrax/citations_behaviors/title_behavior.rb', line 20

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

#process_title_parts(title_text, &block) ⇒ Object


30
31
32
33
34
35
36
# File 'app/helpers/hyrax/citations_behaviors/title_behavior.rb', line 30

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

#setup_title_info(work) ⇒ Object


38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/helpers/hyrax/citations_behaviors/title_behavior.rb', line 38

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