blob: 0463ba6ee96f7c9c6160e37794f827269f2e5578 (
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
|
# frozen_string_literal: true
require 'csv'
class CsvExporter < BaseExporter
def export
str = ''
@things.each do |thing|
str += thing_to_csv(thing:)
end
str
end
protected
# Generate a new CSV line from the given `thing`.
def thing_to_csv(thing:)
CSV.generate_line([thing.target, thing.authors, thing.editors, thing.year,
clean_title(title: thing.title), thing.note, thing.insideof,
thing.url, thing.publisher, thing.kind, thing.access, thing.bought_at],
quote_empty: false)
end
# Clean the given title from underscores and other such characters.
def clean_title(title:)
title.delete('_')
end
end
|