示例#1
0
        private NumberExtractor(NumberMode mode = NumberMode.Default)
        {
            var builder = ImmutableDictionary.CreateBuilder <Regex, string>();

            //Add Cardinal
            CardinalExtractor cardExtract = null;

            switch (mode)
            {
            case NumberMode.PureNumber:
                cardExtract = CardinalExtractor.GetInstance(NumbersDefinitions.PlaceHolderPureNumber);
                break;

            case NumberMode.Currency:
                builder.Add(new Regex(NumbersDefinitions.CurrencyRegex, RegexOptions.Singleline), "IntegerNum");
                break;

            case NumberMode.Default:
                break;
            }

            if (cardExtract == null)
            {
                cardExtract = CardinalExtractor.GetInstance();
            }

            builder.AddRange(cardExtract.Regexes);

            //Add Fraction
            var fracExtract = FractionExtractor.GetInstance();

            builder.AddRange(fracExtract.Regexes);

            Regexes = builder.ToImmutable();
        }
        public static CardinalExtractor GetInstance(string placeholder = NumbersDefinitions.PlaceHolderDefault)
        {
            if (!Instances.ContainsKey(placeholder))
            {
                var instance = new CardinalExtractor(placeholder);
                Instances.TryAdd(placeholder, instance);
            }

            return(Instances[placeholder]);
        }
        public static CardinalExtractor GetInstance(BaseNumberOptionsConfiguration config)
        {
            var extractorKey = config.Placeholder;

            if (!Instances.ContainsKey(extractorKey))
            {
                var instance = new CardinalExtractor(config);
                Instances.TryAdd(extractorKey, instance);
            }

            return(Instances[extractorKey]);
        }