Exemplo n.º 1
0
        private async IAsyncEnumerable <Mapler> GetMaplersEnumerableFromUrlAsync(string url)
        {
            string page = await _scraper.DownloadPageAsync(url).ConfigureAwait(false);

            await foreach (Match match in _scraper.GetMatchesInPageAsync(_maplerRegex, page))
            {
                var mapler = new Mapler()
                {
                    Name  = match.Groups["name"].Value,
                    Job   = match.Groups["job"].Value,
                    Level = int.Parse(match.Groups["level"].Value),
                };

                if (mapler.Job == "Beginner")
                {
                    mapler.Job = mapler.Level switch
                    {
                        var x when x < 30 => "Beginner",
                        var x when x >= 30 && x < 70 => "Beginner (30+)",
                        var x when x >= 70 && x < 120 => "Beginner (70+)",
                                   _ => "Beginner (120+)",
                    };
                }
                else if (mapler.Job == "Islander")
                {
                    mapler.Job = mapler.Level switch
                    {
                        var x when x < 30 => "Islander",
                        var x when x >= 30 && x < 70 => "Islander (30+)",
                        var x when x >= 70 && x < 120 => "Islander (70+)",
                                   _ => "Islander (120+)",
                    };
                }
                else if (mapler.Job == "Camper")
                {
                    mapler.Job = mapler.Level switch
                    {
                        var x when x < 30 => "Camper",
                        var x when x >= 30 && x < 70 => "Camper (30+)",
                        var x when x >= 70 && x < 120 => "Camper (70+)",
                                   _ => "Camper (120+)",
                    };
                }

                yield return(mapler);
            }
        }