From a7791635aa98f012d35f97c3c5288494bbb28e38 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Wed, 13 Mar 2024 18:03:43 +0100 Subject: Initial commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- lib/base_exporter.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 lib/base_exporter.rb (limited to 'lib/base_exporter.rb') diff --git a/lib/base_exporter.rb b/lib/base_exporter.rb new file mode 100644 index 0000000..b040592 --- /dev/null +++ b/lib/base_exporter.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class BaseExporter + def initialize(things:) + @things = things + end + + # Returns a string which forces a new TeX line. + def tex_new_line + '\\\\~\\\\' + end + + # Returns a two-sized array containing the first name and the last name as + # parsed from the `author` string. This method assumes the following format is + # followed: + # - 'Name' -> ['Name', nil] + # - 'Name Surname' -> ['Name', 'Surname'] + # - 'Compound Name Surname' -> ['Compound Name', 'Surname'] + # - 'Name _Surname1 Surname2_' -> ['Name', 'Surname1 Surname2'] + def parse_author(author:) + matches = /(.+)?\s_(.+)_/.match(author) + return matches[1].strip, matches[2].strip if matches&.size == 3 + + a = author.split + return [author, nil] if a.size == 1 + + [a[0..-2].join(' '), a.last] + end +end -- cgit v1.2.3