Skip to content

Commit

Permalink
#1-2 リファクタリング
Browse files Browse the repository at this point in the history
  • Loading branch information
miyaji255 committed Mar 16, 2024
1 parent 07af3b6 commit f9d85b6
Showing 1 changed file with 8 additions and 23 deletions.
31 changes: 8 additions & 23 deletions Epub/KoeBook.Epub/Services/ScrapingNaroService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,7 @@ private record SectionWithChapterTitle(string? title, Section section);
if (item.ChildElementCount == 0)
{
if (!string.IsNullOrWhiteSpace(item.InnerHtml))
{
foreach (var split in ScrapingHelper.SplitBrace(item.InnerHtml))
{
section.Elements.Add(new Paragraph() { Text = split });
}
}
section.Elements.AddRange(ScrapingHelper.SplitBrace(item.InnerHtml).Select(line => new Paragraph() { Text = line }));
}
else if (item.ChildElementCount == 1)
{
Expand Down Expand Up @@ -171,17 +166,7 @@ private record SectionWithChapterTitle(string? title, Section section);
}
else
{
bool isAllRuby = true;
foreach (var tags in item.Children)
{
if (tags.TagName != "RUBY")
{
isAllRuby = false;
break;
}
}

if (!isAllRuby)
if (item.Children.Any(t => t.TagName != "RUBY"))
throw new EbookException(ExceptionType.UnexpectedStructure);

if (!string.IsNullOrWhiteSpace(item.InnerHtml))
Expand Down Expand Up @@ -234,12 +219,12 @@ internal static string GetNcode(string url)

return uri.Segments switch
{
// https://ncode.syosetu.com/n0000a/ のとき
["/", var ncode] when IsAscii(ncode) => ncode.TrimEnd('/'),
// https://ncode.syosetu.com/n0000a/12 のとき
["/", var ncode, var num] when IsAscii(ncode) && num.TrimEnd('/').All(char.IsAsciiDigit) => ncode.TrimEnd('/'),
// https://ncode.syosetu.com/novelview/infotop/ncode/n0000a/ のとき
["/", "novelview/", "infotop/", "ncode/", var ncode] when IsAscii(ncode) => ncode.TrimEnd('/'),
// https://ncode.syosetu.com/n0000a/ のとき
["/", var ncode] when IsAscii(ncode) => ncode.TrimEnd('/'),
// https://ncode.syosetu.com/n0000a/12 のとき
["/", var ncode, var num] when IsAscii(ncode) && num.TrimEnd('/').All(char.IsAsciiDigit) => ncode.TrimEnd('/'),
// https://ncode.syosetu.com/novelview/infotop/ncode/n0000a/ のとき
["/", "novelview/", "infotop/", "ncode/", var ncode] when IsAscii(ncode) => ncode.TrimEnd('/'),
_ => throw new EbookException(ExceptionType.InvalidUrl),
};

Expand Down

0 comments on commit f9d85b6

Please sign in to comment.