public int TransformConsumableToHours()
        {
            if (Consumables.ToLower().Equals("unknown"))
            {
                return(-1);
            }

            var splitConsumable = Consumables.Split(' ');
            int valueInHours    = TransformToHour(int.Parse(splitConsumable[0]), splitConsumable[1]);

            return(valueInHours);
        }
示例#2
0
        /// <summary>
        /// Converts the consumables of a StarShip to Hours
        /// </summary>
        /// <returns>Returns a INT containing the number of hours the consumables will last. Returns -1 if it's not possible to determine.</returns>
        private int GetConsumablesInHours()
        {
            if (string.IsNullOrWhiteSpace(Consumables))
            {
                return(-1);
            }

            string[] parts = Consumables.Split(" ");
            if (parts.Length > 2)
            {
                return(-1);
            }

            int consumableNumber;

            if (!int.TryParse(parts[0], out consumableNumber))
            {
                return(-1);
            }

            if (consumableNumber == 0)
            {
                return(0);
            }

            int hourMultiplier;

            switch (parts[1])
            {
            case "hour":
            case "hours":
                hourMultiplier = 1;
                break;

            case "day":
            case "days":
                hourMultiplier = 24;
                break;

            case "week":
            case "weeks":
                hourMultiplier = 24 * 7;
                break;

            case "month":
            case "months":
                hourMultiplier = 24 * 30;
                break;

            case "year":
            case "years":
                hourMultiplier = 24 * 365;
                break;

            default:
                hourMultiplier = 0;
                break;
            }

            return(consumableNumber * hourMultiplier);
        }