Exemplo n.º 1
0
        public void should_return_the_expected_value(string text, string name, string unit)
        {
            var res = UnitExtractor.ExtractNameAndUnit(text);

            res.name.ShouldBeEqualTo(name);
            res.unit.ShouldBeEqualTo(unit);
        }
Exemplo n.º 2
0
        protected override UnitDescription ExtractUnits(string description, DataSheet dataSheet, List <string> keys, IReadOnlyList <IDimension> supportedDimensions, ref double rank)
        {
            var(_, unit) = UnitExtractor.ExtractNameAndUnit(description);

            if (!string.IsNullOrEmpty(unit))
            {
                unit = ValidateUnit(unit, supportedDimensions);
                rank++;
                return(new UnitDescription(unit));
            }

            if (dataSheet == null)
            {
                return(new UnitDescription());
            }

            var unitKey = dataSheet.GetHeaders().FindHeader(description + "_UNIT");

            if (unitKey == null)
            {
                return(new UnitDescription());
            }

            keys.Remove(unitKey);
            rank++;
            return(new UnitDescription(dataSheet.GetColumn(unitKey).FirstOrDefault(u => !string.IsNullOrEmpty(u)), unitKey));
        }
        protected override UnitDescription ExtractUnits(string description, DataSheet dataSheet, List <string> keys, IReadOnlyList <IDimension> supportedDimensions, ref double rank)
        {
            var(_, unit) = UnitExtractor.ExtractNameAndUnit(description);

            if (string.IsNullOrEmpty(unit))
            {
                return(new UnitDescription());
            }

            unit = ValidateUnit(unit, supportedDimensions);
            if (unit != UnitDescription.InvalidUnit)
            {
                rank++;
            }

            return(new UnitDescription(unit));
        }
Exemplo n.º 4
0
        public string[] ExtractNameAndUnit(string text)
        {
            var res = UnitExtractor.ExtractNameAndUnit(text);

            return(new[] { res.name, res.unit });
        }