public static void Normalize(this FillupEntry entry,
                                     UnitOfMeasure.Distance normalizedDistanceUnit,
                                     UnitOfMeasure.Volume normalizedVolumeUnit)
        {
            if (entry.OdometerUnit != normalizedDistanceUnit)
            {
                entry.OdometerReading *= entry.OdometerUnit == UnitOfMeasure.Distance.Mile
                                             ? MILE_TO_KILOMETER_RATIO
                                             : KILOMETER_TO_MILE_RATIO;

                entry.OdometerUnit = entry.OdometerUnit == UnitOfMeasure.Distance.Mile
                                         ? UnitOfMeasure.Distance.Kilometer
                                         : UnitOfMeasure.Distance.Mile;
            }

            if (entry.PumpUnit != normalizedVolumeUnit)
            {
                entry.FillAmount *= entry.PumpUnit == UnitOfMeasure.Volume.Gallon
                                        ? GALLON_TO_LITER_RATIO
                                        : LITER_TO_GALLON_RATIO;

                entry.PricePerUnit /= entry.PumpUnit == UnitOfMeasure.Volume.Gallon
                                          ? GALLON_TO_LITER_RATIO
                                          : LITER_TO_GALLON_RATIO;

                entry.PumpUnit = entry.PumpUnit == UnitOfMeasure.Volume.Gallon
                                     ? UnitOfMeasure.Volume.Liter
                                     : UnitOfMeasure.Volume.Gallon;
            }
        }
Esempio n. 2
0
        public static string GetEfficiencyString(this double efficiency, UnitOfMeasure.Distance distanceUnit,
                                                 UnitOfMeasure.Volume volumeUnit)
        {
            //standard imperial efficiency abbreviation
            if (distanceUnit == UnitOfMeasure.Distance.Mile &&
                volumeUnit == UnitOfMeasure.Volume.Gallon)
                return string.Format("{0:###.#} mpg", efficiency);

            //standard metric efficiency abbreviation
            if (distanceUnit == UnitOfMeasure.Distance.Kilometer &&
                volumeUnit == UnitOfMeasure.Volume.Liter)
                return string.Format("{0:###.#} km/L", efficiency);
            ;

            //for any case where imperial and metric units are used for either volume or distance
            return string.Format("{0:###.#} {1} per {2}", efficiency, distanceUnit.ToString().ToLower(),
                                 volumeUnit.ToString().ToLower());
        }