aboutsummaryrefslogtreecommitdiff
path: root/lib/csv_exporter.rb
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <msabate@suse.com>2024-03-13 18:03:43 +0100
committerMiquel Sabaté Solà <msabate@suse.com>2024-03-13 18:03:43 +0100
commita7791635aa98f012d35f97c3c5288494bbb28e38 (patch)
treebad987e6b4d10ad2f7cd02e40658d464907595ee /lib/csv_exporter.rb
downloadoperum-a7791635aa98f012d35f97c3c5288494bbb28e38.tar.gz
operum-a7791635aa98f012d35f97c3c5288494bbb28e38.zip
Initial commit
Signed-off-by: Miquel Sabaté Solà <msabate@suse.com>
Diffstat (limited to 'lib/csv_exporter.rb')
-rw-r--r--lib/csv_exporter.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/csv_exporter.rb b/lib/csv_exporter.rb
new file mode 100644
index 0000000..a44815d
--- /dev/null
+++ b/lib/csv_exporter.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+require 'csv'
+
+class CsvExporter < BaseExporter
+ def export
+ str = ''
+ @things.each do |thing|
+ str += thing_to_csv(thing:)
+ end
+
+ str
+ end
+
+ def thing_to_csv(thing:)
+ CSV.generate_line([thing.target, thing.authors, thing.editors, thing.year, thing.title,
+ thing.note, thing.insideof, thing.url, thing.publisher, thing.kind,
+ thing.access, thing.bought_at],
+ quote_empty: false)
+ end
+end