Refactor records
This commit is contained in:
parent
96dff46c14
commit
d2dd282307
38
Records.cs
38
Records.cs
@ -1,17 +1,13 @@
|
||||
using System;
|
||||
using System.CodeDom;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Media.Converters;
|
||||
using System.Windows.Navigation;
|
||||
|
||||
namespace Txt2Bib.Records
|
||||
{
|
||||
public interface IBib {
|
||||
public string Convert(string[] entryLines);
|
||||
public string ToString();
|
||||
}
|
||||
};
|
||||
|
||||
public abstract record ItemType
|
||||
{
|
||||
@ -19,6 +15,12 @@ namespace Txt2Bib.Records
|
||||
{
|
||||
return url.Contains("doi");
|
||||
}
|
||||
protected static string Rearrange(string a)
|
||||
{
|
||||
a = a.Trim();
|
||||
var s = a.Split(' ');
|
||||
return $"{s[1]} {s[0]}";
|
||||
}
|
||||
}
|
||||
|
||||
public record class Article : ItemType, IBib
|
||||
@ -37,16 +39,10 @@ namespace Txt2Bib.Records
|
||||
|
||||
public string Convert(string[] entryLines)
|
||||
{
|
||||
var rearrange = (string a) =>
|
||||
{
|
||||
a = a.Trim();
|
||||
var s = a.Split(' ');
|
||||
return $"{s[1]} {s[0]}";
|
||||
};
|
||||
var checkVol = (string v) =>
|
||||
v.Split(',').Length == 2 ? v.Split(',')[0].Trim() : v.Trim();
|
||||
|
||||
Author = entryLines[1].Split(',').Select(a => rearrange(a)).ToArray();
|
||||
Author = entryLines[1].Split(',').Select(a => Rearrange(a)).ToArray();
|
||||
Year = ushort.Parse(entryLines[2]);
|
||||
Title = entryLines[3];
|
||||
Journal = entryLines[4];
|
||||
@ -102,20 +98,14 @@ namespace Txt2Bib.Records
|
||||
|
||||
public string Convert(string[] entryLines)
|
||||
{
|
||||
var rearrange = (string a) =>
|
||||
{
|
||||
a = a.Trim();
|
||||
var s = a.Split(' ');
|
||||
return $"{s[1]} {s[0]}";
|
||||
};
|
||||
var auths = entryLines[1];
|
||||
if (auths.Contains("eds"))
|
||||
{
|
||||
Editor = auths.Replace("(eds.)", "").Split(',').Select(a => rearrange(a)).ToArray();
|
||||
Editor = auths.Replace("(eds.)", "").Split(',').Select(a => Rearrange(a)).ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
Author = auths.Split(',').Select(a => rearrange(a)).ToArray();
|
||||
Author = auths.Split(',').Select(a => Rearrange(a)).ToArray();
|
||||
}
|
||||
Year = ushort.Parse(entryLines[2]);
|
||||
Title = entryLines[3];
|
||||
@ -176,13 +166,7 @@ namespace Txt2Bib.Records
|
||||
|
||||
public string Convert(string[] entryLines)
|
||||
{
|
||||
var rearrange = (string a) =>
|
||||
{
|
||||
a = a.Trim();
|
||||
var s = a.Split(' ');
|
||||
return $"{s[1]} {s[0]}";
|
||||
};
|
||||
Author = entryLines[1].Split(',').Select(a => rearrange(a)).ToArray();
|
||||
Author = entryLines[1].Split(',').Select(a => Rearrange(a)).ToArray();
|
||||
Year = ushort.Parse(entryLines[2]);
|
||||
Title = entryLines[3];
|
||||
BookTitle = entryLines[4];
|
||||
|
Loading…
Reference in New Issue
Block a user