diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/csv_exporter.rb | 14 | ||||
| -rw-r--r-- | lib/uoc_exporter.rb | 21 |
2 files changed, 31 insertions, 4 deletions
diff --git a/lib/csv_exporter.rb b/lib/csv_exporter.rb index a44815d..0463ba6 100644 --- a/lib/csv_exporter.rb +++ b/lib/csv_exporter.rb @@ -12,10 +12,18 @@ class CsvExporter < BaseExporter 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, thing.title, - thing.note, thing.insideof, thing.url, thing.publisher, thing.kind, - thing.access, thing.bought_at], + 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 diff --git a/lib/uoc_exporter.rb b/lib/uoc_exporter.rb index 9a83d7c..e8dcc62 100644 --- a/lib/uoc_exporter.rb +++ b/lib/uoc_exporter.rb @@ -16,7 +16,7 @@ class UocExporter < BaseExporter # Returns the head of a line, containing authors, year, title and, if # available, the "inside of" information. def head(thing:) - str = "#{parse_authors(thing:)} (#{thing.year}). \\emph{#{thing.title}}." + str = "#{parse_authors(thing:)} (#{thing.year}). #{parse_title(title: thing.title)}." if thing.insideof.present? str += " #{inside_of(thing.insideof)}" @@ -26,6 +26,25 @@ class UocExporter < BaseExporter str end + # Returns the title without underscores and with the expected formatting. + def parse_title(title:) + str = '' + seen = false + + # I'm sure there is a clever (and comboluted) regexp that can also achieve + # this, but after some tries I decided to cut the crap. + title.each_char do |c| + if c == '_' + str += seen ? '\emph{' : '}' + seen = !seen + else + str += c + end + end + + "\\emph{#{str}}" + end + # Parse the authors as delivered by `thing.authors` and render them in the # proper format. def parse_authors(thing:) |
