コード例 #1
0
        public static double GetMiniConversionConstant(this YarnType yarnType)
        {
            YarnTypePropertiesAttribute yarnTypePropertiesAttribute = GetYarnTypeProperties(yarnType);
            double conversionConstant = yarnTypePropertiesAttribute.MiniConversionConstant;

            return(conversionConstant);
        }
コード例 #2
0
        public static YarnType GetCorrespondingMiniType(this YarnType yarnType)
        {
            YarnTypePropertiesAttribute yarnTypePropertiesAttribute = GetYarnTypeProperties(yarnType);
            YarnType miniType = yarnTypePropertiesAttribute.CorrespondingMiniType;

            return(miniType);
        }
コード例 #3
0
        public void CreateYarnTypeCodeFromTextShouldReturnYarnTypeCodeAsBFLSock()
        {
            String typeCode = "BSK";

            YarnType yarnType = YarnFactory.CreateYarnTypeFromText(typeCode);

            Assert.AreEqual(YarnType.BFLSock, yarnType);
        }
コード例 #4
0
        public void ModifyValuesForMiniSkeinsShouldNotModifyValuesWhenDescriptionDoesNotContainANumber()
        {
            string   yarnDescription = "Classy S.W. Merino Worsted";
            double   quantity        = 2;
            YarnType yarnType        = YarnType.Classy;

            (YarnType updatedYarnType, double updatedQuantity) = YarnFactory.ModifyValuesForMiniSkeins(yarnDescription, quantity, yarnType);

            Assert.AreEqual(YarnType.Classy, updatedYarnType);
            Assert.AreEqual(2, updatedQuantity);
        }
コード例 #5
0
        public void ModifyValuesForMiniSkeinsShouldModifyValuesWhenDescriptionContainsANumber()
        {
            string   yarnDescription = "Classy 5- 50yd.minis @ $2.90 per skein";
            double   quantity        = 2;
            YarnType yarnType        = YarnType.Classy;

            (YarnType updatedYarnType, double updatedQuantity) = YarnFactory.ModifyValuesForMiniSkeins(yarnDescription, quantity, yarnType);

            Assert.AreEqual(YarnType.MiniClassy, updatedYarnType);
            Assert.AreEqual(10, updatedQuantity);
        }
コード例 #6
0
        public static (YarnType, double) ModifyValuesForMiniSkeins(string yarnDescription, double quantity,
                                                                   YarnType yarnType)
        {
            if (Yarn.DetermineIfMiniSkein(yarnDescription))
            {
                double conversionConstant = yarnType.GetMiniConversionConstant();
                quantity *= conversionConstant;
                YarnType miniType = yarnType.GetCorrespondingMiniType();
                return(miniType, quantity);
            }

            return(yarnType, quantity);
        }
コード例 #7
0
        public static String GetTextRepresentation(this YarnType yarnType)
        {
            YarnTypePropertiesAttribute yarnTypePropertiesAttribute = GetYarnTypeProperties(yarnType);
            String textRepresentation = yarnTypePropertiesAttribute.TextRepresentation;

            if (textRepresentation != String.Empty)
            {
                return(textRepresentation);
            }
            else
            {
                return(yarnType.ToString());
            }
        }
コード例 #8
0
ファイル: Yarn.cs プロジェクト: Mleuer/DyeListGenerator
        public static Yarn CreateYarnFromText(CsvReader reader)
        {
            double   quantity            = reader.GetField <double>(1);
            YarnType yarnType            = YarnFactory.CreateYarnTypeFromText(reader.GetField <String>(2));
            String   yarnTypeDescription = reader.GetField <String>(3);

            (yarnType, quantity) = YarnFactory.ModifyValuesForMiniSkeins(yarnTypeDescription, quantity, yarnType);

            Yarn yarn = new Yarn(quantity, yarnType, yarnTypeDescription);

            if (reader.TryGetField <String>(4, out String colorName))
            {
                yarn.Color = colorName;
            }

            return(yarn);
        }
コード例 #9
0
ファイル: Yarn.cs プロジェクト: Mleuer/DyeListGenerator
        public static Yarn CreateYarnFromText(string inputText)
        {
            inputText = inputText.TrimStart(',');
            String[] inputs = inputText.Split(',');

            double   quantity            = double.Parse(inputs[0]);
            YarnType yarnType            = YarnFactory.CreateYarnTypeFromText(inputs[1]);
            String   yarnTypeDescription = inputs[2];

            (yarnType, quantity) = YarnFactory.ModifyValuesForMiniSkeins(yarnTypeDescription, quantity, yarnType);

            Yarn yarn = new Yarn(quantity, yarnType, yarnTypeDescription);

            if (inputs.Length > 3)
            {
                yarn.Color = inputs[3];
            }

            return(yarn);
        }
コード例 #10
0
        private static YarnTypePropertiesAttribute GetYarnTypeProperties(YarnType yarnType)
        {
            Type type = yarnType.GetType();

            string name = Enum.GetName(type, yarnType);

            if (name != null)
            {
                FieldInfo field = type.GetField(name);
                if (field != null)
                {
                    YarnTypePropertiesAttribute yarnTypeProperties =
                        Attribute.GetCustomAttribute(field, typeof(YarnTypePropertiesAttribute)) as YarnTypePropertiesAttribute;
                    if (yarnTypeProperties != null)
                    {
                        return(yarnTypeProperties);
                    }
                }
            }

            throw new ArgumentException();
        }
コード例 #11
0
ファイル: Yarn.cs プロジェクト: Mleuer/DyeListGenerator
 public Yarn(double numberOfSkeins, YarnType yarnType, String yarnTypeDescription)
 {
     NumberOfSkeins      = numberOfSkeins;
     YarnType            = yarnType;
     YarnTypeDescription = yarnTypeDescription;
 }
コード例 #12
0
 public YarnTypePropertiesAttribute(double miniConversionConstant, YarnType miniType, string textRepresentation = "")
 {
     MiniConversionConstant = miniConversionConstant;
     CorrespondingMiniType  = miniType;
     TextRepresentation     = textRepresentation;
 }