Пример #1
0
        public static IEnumerable <Emoji> Parse(IHtmlDocument document)
        {
            var rows = document
                       .GetNodes <IHtmlTableRowElement>(predicate: row =>
                                                        row.Cells.Length >= _headers.Length &&           // Filter out rows that don't have enough cells.
                                                        row.Cells.All(x => x.LocalName == TagNames.Td)); // We're only interested in td cells, not th.

            foreach (var row in rows)
            {
                var dictionary = _headers
                                 .Zip(row.Cells, (header, cell) => (Header: header, cell.TextContent.Trim()))
                                 .ToDictionary(x => x.Item1, x => x.Item2);

                var code       = TransformCode(dictionary["code"]);
                var identifier = TransformName(dictionary["name"])
                                 .Replace("-", "_")
                                 .Replace("(", string.Empty)
                                 .Replace(")", string.Empty);

                var description = dictionary["name"].Humanize();

                var name = identifier
                           .Replace("1st", "first")
                           .Replace("2nd", "second")
                           .Replace("3rd", "third")
                           .Pascalize();

                yield return(new Emoji(identifier, name, code, description));
            }
        }