Process book records correctly

This commit is contained in:
Nicolò P 2024-01-12 12:07:03 +01:00
parent 5e0c737423
commit 356dc796c8
2 changed files with 30 additions and 7 deletions

View File

@ -71,7 +71,7 @@ namespace Txt2Bib.Records
public override string ToString() public override string ToString()
{ {
return $"@{Type}{{{Author[0][..5]}_{Year},\n" + return $"@{Type}{{{Author[0][..5].Replace(". ", "_")}_{Year},\n" +
$"\tauthor = \"{string.Join(" and ", Author)}\",\n" + $"\tauthor = \"{string.Join(" and ", Author)}\",\n" +
$"\ttitle = {{{Title}}},\n" + $"\ttitle = {{{Title}}},\n" +
$"\tjournal = \"{Journal}\",\n" + $"\tjournal = \"{Journal}\",\n" +
@ -88,7 +88,8 @@ namespace Txt2Bib.Records
public record class BookBib : IBib public record class BookBib : IBib
{ {
public string Type { get; init; } = "book"; public string Type { get; init; } = "book";
public string[] Author { get; set; } = { "Gianni e Pinotto" }; public string[] Author { get; set; } = Array.Empty<string>();
public string[] Editor { get; set; } = Array.Empty<string>();
public string Title { get; set; } = ""; public string Title { get; set; } = "";
public ushort Year { get; set; } = 1950; public ushort Year { get; set; } = 1950;
public string Publisher { get; set; } = ""; public string Publisher { get; set; } = "";
@ -104,7 +105,15 @@ namespace Txt2Bib.Records
var s = a.Split(' '); var s = a.Split(' ');
return $"{s[1]} {s[0]}"; return $"{s[1]} {s[0]}";
}; };
Author = entryLines[1].Split(',').Select(a => rearrange(a)).ToArray(); var auths = entryLines[1];
if (auths.Contains("eds"))
{
Editor = auths.Replace("(eds.)", "").Split(',').Select(a => rearrange(a)).ToArray();
}
else
{
Author = auths.Split(',').Select(a => rearrange(a)).ToArray();
}
Year = ushort.Parse(entryLines[2]); Year = ushort.Parse(entryLines[2]);
Title = entryLines[3]; Title = entryLines[3];
Place = entryLines[4]; Place = entryLines[4];
@ -126,13 +135,28 @@ namespace Txt2Bib.Records
public override string ToString() public override string ToString()
{ {
return $"@{Type}{{{Author[0][..5]}_{Year},\n" + var label = "";
$"\tauthor = \"{string.Join(" and ", Author)}\",\n" + var authString = "";
if (Author.Length != 0)
{
label = Author[0][..5].Replace(". ", "");
authString = $"\tauthor = \"{string.Join(" and ", Author)}\",\n";
}
else
{
label = Editor[0][..5].Replace(". ", "");
authString = $"\teditor = \"{string.Join(" and ", Editor)}\",\n";
}
return $"@{Type}{{{label}_{Year},\n" +
authString +
$"\ttitle = {{{Title}}},\n" + $"\ttitle = {{{Title}}},\n" +
$"\tpublisher = \"{Publisher}\",\n" + $"\tpublisher = \"{Publisher}\",\n" +
$"\taddress = \"{Place}\",\n" + $"\taddress = \"{Place}\",\n" +
$"\tyear = \"{Year}\",\n" + $"\tyear = \"{Year}\",\n" +
$"\turl = \"{Url}\",\n" + $"\turl = \"{Url}\",\n" +
$"\tdoi = \"{Doi}\",\n" +
"}\n"; "}\n";
} }
} }

View File

@ -77,8 +77,7 @@ namespace Txt2Bib
if (!IsValidEntry(type)) throw new Exception($"Invalid entry type '{type}'"); if (!IsValidEntry(type)) throw new Exception($"Invalid entry type '{type}'");
string citation = ""; string citation;
try try
{ {
citation = type switch citation = type switch