blob: 514d243fedb6240bc880b17c9bf5bc2804d1b6e6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# frozen_string_literal: true
# Plain text exporter.
class PlainExporter < BaseExporter
def export
@things.map { |thing| "#{head(thing:)} #{body(thing:)}".strip }.join("\n")
end
protected
# Returns the same text as the plain exporter does not have formatting.
def emph(text:)
text
end
# Returns the same text as the plain exporter does not have formatting.
def upper_case(text:)
text
end
# Returns the same text with underscores stripped, as the plain exporter does
# not have formatting.
def parse_title(title:)
title.delete('_')
end
# Returns text with information on the publisher, notes, year, address, etc;
# if available.
def body(thing:)
str = ''
if thing.publisher.present?
str += thing.note.present? ? "#{thing.note}. #{thing.publisher}" : thing.publisher
end
if thing.address.present?
str + ", #{thing.address}: #{thing.year}."
else
"#{str}."
end
end
end
|