Some refactoring...
This commit is contained in:
parent
82cde40bee
commit
a1b8218ed4
26
Records.cs
26
Records.cs
@ -13,7 +13,15 @@ namespace Txt2Bib.Records
|
||||
public string ToString();
|
||||
}
|
||||
|
||||
public record class ArticleBib : IBib
|
||||
public abstract record ItemType
|
||||
{
|
||||
protected static bool IsDoi(string url)
|
||||
{
|
||||
return url.Contains("doi");
|
||||
}
|
||||
}
|
||||
|
||||
public record class Article : ItemType, IBib
|
||||
{
|
||||
public string Type { get; init; } = "article";
|
||||
public string[] Author { get; set; } = { "Gianni e Pinotto" };
|
||||
@ -64,11 +72,6 @@ namespace Txt2Bib.Records
|
||||
return ToString();
|
||||
}
|
||||
|
||||
private bool IsDoi(string url)
|
||||
{
|
||||
return url.Contains("doi");
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"@{Type}{{{Author[0][..5].Replace(". ", "_")}_{Year},\n" +
|
||||
@ -85,7 +88,7 @@ namespace Txt2Bib.Records
|
||||
}
|
||||
}
|
||||
|
||||
public record class BookBib : IBib
|
||||
public record class Book : ItemType, IBib
|
||||
{
|
||||
public string Type { get; init; } = "book";
|
||||
public string[] Author { get; set; } = Array.Empty<string>();
|
||||
@ -128,15 +131,10 @@ namespace Txt2Bib.Records
|
||||
return ToString();
|
||||
}
|
||||
|
||||
private bool IsDoi(string url)
|
||||
{
|
||||
return url.Contains("doi");
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var label = "";
|
||||
var authString = "";
|
||||
string label;
|
||||
string authString;
|
||||
|
||||
if (Author.Length != 0)
|
||||
{
|
||||
|
@ -15,7 +15,7 @@ namespace Txt2Bib
|
||||
/// </summary>
|
||||
public class Text2Bib
|
||||
{
|
||||
private string[] _citTypes = { "J", "B", "C", "P", "?" };
|
||||
private string[] _citTypes = { "J", "B", "C", "P", "I" };
|
||||
|
||||
/// <summary>
|
||||
/// Generate single .bib file from input text files
|
||||
@ -41,7 +41,7 @@ namespace Txt2Bib
|
||||
/// <returns></returns>
|
||||
public string CreateBibTeX(string path)
|
||||
{
|
||||
var reader = File.OpenText(path);
|
||||
using var reader = File.OpenText(path);
|
||||
byte[] contentBytes = File.ReadAllBytes(path);
|
||||
var content = Encoding.Latin1.GetString(contentBytes);
|
||||
|
||||
@ -82,8 +82,8 @@ namespace Txt2Bib
|
||||
{
|
||||
citation = type switch
|
||||
{
|
||||
"J" => (new ArticleBib()).Convert(lines),
|
||||
"B" => new BookBib().Convert(lines),
|
||||
"J" => (new Article()).Convert(lines),
|
||||
"B" => new Book().Convert(lines),
|
||||
//"C" => new ChapterBib(),
|
||||
//"P" => new ConferenceBib(),
|
||||
_ => ""
|
||||
|
@ -5,7 +5,7 @@
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWPF>true</UseWPF>
|
||||
<Version>0.1.0</Version>
|
||||
<Version>0.1.1</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
Loading…
Reference in New Issue
Block a user