Ejemplo n.º 1
0
 private string[] Pattern(Nokogiri.Node node, string selector)
 {
     return(TextOrEmpty(node, selector)
            .Select(Squish)
            .Where(NotNullOrEmpty)
            .ToArray());
 }
Ejemplo n.º 2
0
        private static string[] TextOrEmpty(Nokogiri.Node node, string selector)
        {
            var nodes = node.Search(selector);

            return(nodes == null || !nodes.Any()
                ? new string[0]
                : nodes.Select(n => n.Text).ToArray());
        }
Ejemplo n.º 3
0
        private string[] PossibleNumberPattern(Nokogiri.Node node)
        {
            var nodes = node.Search("fixedLine possibleLengths").FirstOrDefault();

            if (nodes != null)
            {
                return(new string[] { $"\\d{{{(nodes["localOnly"]+","+nodes["national"]).Trim(',')}}}" });
            }

            return(new string[] {});
        }
Ejemplo n.º 4
0
        private IEnumerable <string[]> ExampleNumbersForTerritoryNode(Nokogiri.Node node)
        {
            var name = TerritoryName(node);

            if (name == "001")
            {
                return new[] { new string[0] }
            }
            ;
            return(node.Search(example_numbers_selector())
                   .Select(node1 => new[] { node1.Text, name })
                   .ToArray());
        }
Ejemplo n.º 5
0
        private IDictionary CompileFormat(Nokogiri.Node node)
        {
            var format = new Dictionary <string, object>
            {
                { "pattern", node["pattern"] },
                { "format", TextOrEmpty(node, "format").FirstOrDefault() },
                { "leadingDigits", Pattern(node, "leadingDigits") },
                { "formatRule", node["nationalPrefixFormattingRule"] },
                { "intlFormat", TextOrEmpty(node, "intlFormat").FirstOrDefault() },
            };

            return(format);
        }
Ejemplo n.º 6
0
        private IDictionary CompileTerritory(Nokogiri.Node node)
        {
            var possibleNumberPattern = Pattern(node, "generalDesc possibleNumberPattern");
            var nationalNumberPattern = Pattern(node, "generalDesc nationalNumberPattern");
            var d = new Dictionary <string, object>
            {
                { "name", TerritoryName(node) },
                { "possibleNumber", possibleNumberPattern.FirstOrDefault() },
                { "nationalNumber", nationalNumberPattern.FirstOrDefault() },
                { "formattingRule", Squish(node["nationalPrefixFormattingRule"]) },
                { "nationalPrefix", Squish(node["nationalPrefix"]) },
            };

            if ("true".Equals(Squish(node["nationalPrefixOptionalWhenFormatting"])))
            {
                d.Add("nationalPrefixOptionalWhenFormatting", true);
            }
            return(d);
        }
Ejemplo n.º 7
0
 private static string TerritoryName(Nokogiri.Node node)
 {
     return(node["id"]);
 }