Created
January 11, 2023 00:26
-
-
Save sgade/5d566c13c9c334448316bcf4c3ae30cb to your computer and use it in GitHub Desktop.
Swift: UnitElectricEnergyEfficiency
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UnitElectricEnergyEfficiency.swift | |
// | |
// Created by Sören Gade on 13.12.21. | |
// Copyright © 2021 Sören Gade. All rights reserved. | |
// | |
import Foundation | |
/// A unit of measure for electric energy efficiency. | |
/// | |
/// # Overview | |
/// | |
/// You typically use instances of `UnitElectricEnergyEfficiency` to represent specific quantities of fuel efficiency | |
/// using the `Measurement` class. | |
/// | |
/// ## Electric Energy Efficiency | |
/// | |
/// Electric energy efficiency corresponds to the efficiency of a process that converts electric energy into kinetic | |
/// energy. | |
/// Eletric energy efficiency can be expressed by SI derived units in terms of joule per meter (J/m), but is more | |
/// commonly expressed in terms of kilowatt hours per kilometer. | |
/// | |
/// The `UnitElectricEnergyEfficiency` class defines its base unit as `wattHoursPerKilometer`, | |
/// and provides the following units: | |
/// | |
/// | Name | Method | Symbol | | |
/// |----------------------------------|---------------------------------|-----------| | |
/// | Watt Hours Per Kilometer | `wattHoursPerKilometer` | wH/km | | |
/// | Kilowatt Hours Per Kilometer | `kilowattHoursPerKilometer` | kWh/km | | |
/// | Kilowatt Hours Per 100 Kilometer | `kilowattHoursPer100Kilometers` | kWh/100km | | |
/// | |
public class UnitElectricEnergyEfficiency: Dimension { | |
public override class func baseUnit() -> Self { | |
Self.joulePerMeter as! Self | |
} | |
private static var joulePerMeter = UnitElectricEnergyEfficiency(symbol: "J/m", converter: UnitConverter()) | |
private static var joulePerKilometer = UnitElectricEnergyEfficiency(symbol: "J/km", | |
converter: UnitConverterLinear(coefficient: 1/1000)) | |
/// Returns the watt hours per kilometer unit of electric energy efficiency. | |
public static var wattHoursPerKilometer = UnitElectricEnergyEfficiency(symbol: "Wh/km", | |
converter: UnitConverterLinear(coefficient: 3600 / 1000)) | |
/// Returns the kilowatt hours per kilometer unit of electric energy efficiency. | |
public static var kilowattHoursPerKilometer = UnitElectricEnergyEfficiency(symbol: "kWh/km", | |
converter: UnitConverterLinear(coefficient: (3600 * 1000) / 1000)) | |
/// Returns the kilowatt hours per 100 kilometers unit of electric energy efficiency. | |
public static var kilowattHoursPer100Kilometers = UnitElectricEnergyEfficiency(symbol: "kWh/100km", | |
converter: UnitConverterLinear(coefficient: (3600 * 1000) / (1000 * 100))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment