/// <summary> /// Parse data from account balance box /// </summary> /// <param name="node"></param> /// <returns></returns> private AccountBalance ResolveBalanceBox(HtmlNode node) { var accountBalance = new AccountBalance(); foreach (var tr in node.SelectNodes(".//table[@class='data']/tr")) { var td = tr.SelectNodes(".//td"); switch (td[0].InnerText.Trim()) { case var name when name.Equals("Available Funds", StringComparison.InvariantCultureIgnoreCase): accountBalance.AvailableFunds = ParserHelpers.ParseDecimal(td[1].InnerText); break; case var name when name.Equals("Invested Funds", StringComparison.InvariantCultureIgnoreCase): accountBalance.InvestedFunds = ParserHelpers.ParseDecimal(td[1].InnerText); break; } } return(accountBalance); }
/// <summary> /// Parse data for one currency /// </summary> /// <param name="node"></param> /// <param name="currency"></param> /// <returns></returns> private InvestorOverview GetBox(HtmlNode node, Currency currency) { var boxes = node.SelectNodes(".//li[@class='overview-box']"); // Resolve first box var accountBalance = ResolveBalanceBox(boxes[0]); // Resolve second box var accountProfit = ResolveProfitBox(boxes[1]); // Resolve category box"es" var loanCategories = ((LoanStatus[])Enum.GetValues(typeof(LoanStatus))) .Select(e => new LoanCategory() { PaymentStatus = e }) .ToList(); var categoryBoxes = boxes[2].SelectNodes(".//ul[@class='m-investment-totals']/li"); ResolveCategoryBox(categoryBoxes[0], loanCategories, (category, text) => category.Amount = ParserHelpers.ParseDecimal(text)); ResolveCategoryBox(categoryBoxes[1], loanCategories, (category, text) => category.Count = ParserHelpers.ParseInteger(text)); return(new InvestorOverview() { Currency = currency, AccountBalance = accountBalance, AccountProfit = accountProfit, LoanCategories = loanCategories }); }