Commit 0f8bc252 authored by nanahira's avatar nanahira

use function instead

parent d1bc3354
...@@ -33,22 +33,17 @@ function getPlayerRowFromTree(tree: HTML.Tree): PlayerRow { ...@@ -33,22 +33,17 @@ function getPlayerRowFromTree(tree: HTML.Tree): PlayerRow {
} }
} }
export class PlayerList {
rows: PlayerRow[];
private parseRows(content: string) { export function parsePlayerRows(content: string) {
this.rows = [];
const parsedContent = HTML(content); const parsedContent = HTML(content);
const tablePos = findNodeIndexByTag(parsedContent, "table", []); const tablePos = findNodeIndexByTag(parsedContent, "table", []);
const tableTree = getDepthOfTree(parsedContent, tablePos); const tableTree = getDepthOfTree(parsedContent, tablePos);
const playerPoses = findAllNodeIndex(tableTree, (node) => { const playerPoses = findAllNodeIndex(tableTree, (node) => {
return typeof (node) !== "string" && node.tag === "tr" && node.attrs.class !== "trTop2"; return typeof (node) !== "string" && node.tag === "tr" && node.attrs.class !== "trTop2";
}, []); }, []);
this.rows = playerPoses.map(pos => { return playerPoses.map(pos => {
const tree = getDepthOfTree(tableTree, pos); const tree = getDepthOfTree(tableTree, pos);
return getPlayerRowFromTree(tree); return getPlayerRowFromTree(tree);
}) });
}
constructor(content: string) {
this.parseRows(content);
}
} }
import { User } from "../src/user"; import { User } from "../src/user";
import fs from "fs"; import fs from "fs";
import { PlayerList } from "../src/playerlist";
async function main() { async function main() {
let html = await fs.promises.readFile("./tests/playerlist.html", "utf-8"); let html = await fs.promises.readFile("./tests/28_20588.html", "utf-8");
console.log(new PlayerList(html)); console.log(new User("28_20588", html, null));
html = await fs.promises.readFile("./tests/playerlist-null.html", "utf-8"); html = await fs.promises.readFile("./tests/60_46782.html", "utf-8");
console.log(new PlayerList(html)); console.log(new User("60_46782", html, null));
} }
main(); main();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment