Commit 0f8bc252 authored by nanahira's avatar nanahira

use function instead

parent d1bc3354
......@@ -33,22 +33,17 @@ function getPlayerRowFromTree(tree: HTML.Tree): PlayerRow {
}
}
export class PlayerList {
rows: PlayerRow[];
private parseRows(content: string) {
this.rows = [];
const parsedContent = HTML(content);
const tablePos = findNodeIndexByTag(parsedContent, "table", []);
const tableTree = getDepthOfTree(parsedContent, tablePos);
const playerPoses = findAllNodeIndex(tableTree, (node) => {
return typeof (node) !== "string" && node.tag === "tr" && node.attrs.class !== "trTop2";
}, []);
this.rows = playerPoses.map(pos => {
const tree = getDepthOfTree(tableTree, pos);
return getPlayerRowFromTree(tree);
})
}
constructor(content: string) {
this.parseRows(content);
}
export function parsePlayerRows(content: string) {
const parsedContent = HTML(content);
const tablePos = findNodeIndexByTag(parsedContent, "table", []);
const tableTree = getDepthOfTree(parsedContent, tablePos);
const playerPoses = findAllNodeIndex(tableTree, (node) => {
return typeof (node) !== "string" && node.tag === "tr" && node.attrs.class !== "trTop2";
}, []);
return playerPoses.map(pos => {
const tree = getDepthOfTree(tableTree, pos);
return getPlayerRowFromTree(tree);
});
}
import { User } from "../src/user";
import fs from "fs";
import { PlayerList } from "../src/playerlist";
async function main() {
let html = await fs.promises.readFile("./tests/playerlist.html", "utf-8");
console.log(new PlayerList(html));
html = await fs.promises.readFile("./tests/playerlist-null.html", "utf-8");
console.log(new PlayerList(html));
let html = await fs.promises.readFile("./tests/28_20588.html", "utf-8");
console.log(new User("28_20588", html, null));
html = await fs.promises.readFile("./tests/60_46782.html", "utf-8");
console.log(new User("60_46782", html, null));
}
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