Module: AsciidocBib::CitationUtils

Included in:
Citations
Defined in:
lib/asciidoc-bib/citationutils.rb

Overview

Some utility functions used in Citations class

Constant Summary collapse

CITATION =

matches a single ref with optional pages

/([\w\-]+)(,([\w\.\- ]+))?/
CITATION_FULL =

matches complete citation with multiple references

/\[(cite|citenp):(([\w\-\;\!\? ]+):)?(#{CITATION}(;#{CITATION})*)\]/

Instance Method Summary collapse

Instance Method Details

#arrange_authors(authors, surname_first) ⇒ Object

Arrange author string, flag for order of surname/initials.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/asciidoc-bib/citationutils.rb', line 28

def arrange_authors authors, surname_first 
  return [] if authors.nil?
  authors.split(/\band\b/).collect do |name|
    if name.include?(", ")
      parts = name.strip.rpartition(", ")
      if surname_first
        "#{parts.first}, #{parts.third}"
      else
        "#{parts.third} #{parts.first}"
      end
    else
      name
    end
  end
end

#author_chicago(authors) ⇒ Object

Arrange given author string into Chicago format.



45
46
47
# File 'lib/asciidoc-bib/citationutils.rb', line 45

def author_chicago authors 
  arrange_authors authors, true 
end

#retrieve_citations(line) ⇒ Object

Given a line, return a list of CitationData instances containing information on each set of citation information.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/asciidoc-bib/citationutils.rb', line 8

def retrieve_citations line
  result = []
  md = CITATION_FULL.match line
  while md
    data = CitationData.new md[0], md[1], md[3], []
    cm = CITATION.match md[4]
    while cm
      data.cites << Citation.new(cm[1], cm[3])
      # look for next ref within citation
      cm = CITATION.match cm.post_match 
    end
    result << data
    # look for next citation on line
    md = CITATION_FULL.match md.post_match 
  end

  return result
end