Input file is an excel file and the excel file has headers like author, 2ndauthor, 3rdauthor.
So the input xlsx looks like
Title Author 2ndAuthor 3rdAuthor 4thAuthor
E=MC^2 Einstein
DNA Watson Crick
AAA BB BBB CCC
But currently the ruby on rails program does something like
if not contents["#{record.title} (#{record.author} paper)"]
contents += "*[[#{record.title} (#{record.author} paper)]]\r\n"
end
So the output of the ruby program looks like
E=MC^2 (Einstein paper)
DNA (Watson paper)
AAA (BB paper)
But I want to include 2ndauthor, 3rdauthor,... to get
E=MC^2 (Einstein paper)
DNA (Watson and Crick paper)
AAA (BB, BBB, and CCC paper)
So, comma is added between authors only when there are 3 or more than 3 authors.
Is there any brilliant way to do this?
added question
If
"#{title} (#{author} paper)"
was generating
AAA (BB paper)
then will
"#{title}" + " ([#{author},#{2ndauthor},#{3rdauthor},#{4thauthor}].delete_if{|val| val.nil?}.to_sentence" + " paper)"
generate
AAA (BB, BBB, and CCC paper)
?