Class: Formatters::ReferenceFormatter
- Inherits:
-
Object
- Object
- Formatters::ReferenceFormatter
show all
- Extended by:
- ERB::Util
- Includes:
- ERB::Util
- Defined in:
- lib/formatters/reference_formatter.rb
Class Method Summary
(collapse)
Instance Method Summary
(collapse)
Constructor Details
- (ReferenceFormatter) initialize(reference)
A new instance of ReferenceFormatter
33
34
35
|
# File 'lib/formatters/reference_formatter.rb', line 33
def initialize reference
@reference = reference
end
|
Class Method Details
+ (Object) add_period_if_necessary(string)
21
22
23
24
25
26
|
# File 'lib/formatters/reference_formatter.rb', line 21
def self.add_period_if_necessary string
return unless string
return string if string.empty?
return string + '.' unless string[-1..-1] =~ /[.!?]/
string
end
|
6
7
8
|
# File 'lib/formatters/reference_formatter.rb', line 6
def self.format reference
make_formatter(reference).format
end
|
9
10
11
|
# File 'lib/formatters/reference_formatter.rb', line 9
def self.format_inline_citation reference, user
make_formatter(reference).format_inline_citation user
end
|
28
29
30
|
# File 'lib/formatters/reference_formatter.rb', line 28
def self.format_timestamp timestamp
timestamp.strftime '%Y-%m-%d'
end
|
+ (Object) italicize(string)
13
14
15
16
17
18
19
|
# File 'lib/formatters/reference_formatter.rb', line 13
def self.italicize string
return unless string
raise "Can't italicize an unsafe string" unless string.html_safe?
string = string.gsub /\*(.*?)\*/, '<span class=genus_or_species>\1</span>'
string = string.gsub /\|(.*?)\|/, '<span class=genus_or_species>\1</span>'
string.html_safe
end
|
Instance Method Details
37
38
39
40
41
42
43
44
45
|
# File 'lib/formatters/reference_formatter.rb', line 37
def format
string = format_author_names
string << ' ' unless string.empty?
string << format_year << '. '
string << format_title << ' '
string << format_citation
string << " [#{format_date(@reference.date)}]" if @reference.date?
string
end
|
47
48
49
|
# File 'lib/formatters/reference_formatter.rb', line 47
def format_author_names
h @reference.author_names_string
end
|
59
60
61
|
# File 'lib/formatters/reference_formatter.rb', line 59
def format_inline_citation user
@reference.key.to_link user
end
|
55
56
57
|
# File 'lib/formatters/reference_formatter.rb', line 55
def format_title
self.class.italicize self.class.add_period_if_necessary h @reference.title
end
|
51
52
53
|
# File 'lib/formatters/reference_formatter.rb', line 51
def format_year
h @reference.citation_year
end
|