soumya92/barista

View on GitHub
format/siunit.go

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
// Copyright 2018 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Code generated by siunit.rb; DO NOT EDIT.

package format

import "github.com/martinlindhe/unit"

// SIUnit formats a unit.Unit value to an appropriately scaled base unit.
// For example, SIUnit(length) is equivalent to SI(length.Meters(), "m").
// For non-base units (e.g. feet), use SI(length.Feet(), "ft").
func SIUnit(val interface{}) (Value, bool) {
    switch v := val.(type) {
    case unit.Acceleration:
        return SI(v.MetersPerSecondSquared(), "m/s²"), true
    case unit.Angle:
        return SI(v.Radians(), "rad"), true
    case unit.Area:
        return SI(v.SquareMeters(), "m²"), true
    case unit.Datarate:
        return SI(v.BytesPerSecond(), "B/s"), true
    case unit.Datasize:
        return SI(v.Bytes(), "B"), true
    case unit.ElectricCurrent:
        return SI(v.Amperes(), "A"), true
    case unit.Energy:
        return SI(v.Joules(), "J"), true
    case unit.Force:
        return SI(v.Newtons(), "N"), true
    case unit.Frequency:
        return SI(v.Hertz(), "Hz"), true
    case unit.Length:
        return SI(v.Meters(), "m"), true
    case unit.Mass:
        return SI(v.Grams(), "g"), true
    case unit.Power:
        return SI(v.Watts(), "W"), true
    case unit.Pressure:
        return SI(v.Pascals(), "Pa"), true
    case unit.Speed:
        return SI(v.MetersPerSecond(), "m/s"), true
    case unit.Voltage:
        return SI(v.Volts(), "V"), true
    case unit.Volume:
        return SI(v.CubicMeters(), "m³"), true
    case unit.AmountOfSubstance:
        return SI(v.Moles(), "mol"), true
    case unit.ElectricalConductance:
        return SI(v.Siemens(), "S"), true
    case unit.ElectricalResistance:
        return SI(v.Ohms(), "Ω"), true
    case unit.Illuminance:
        return SI(v.Lux(), "lx"), true
    case unit.LuminousFlux:
        return SI(v.Lumen(), "lm"), true
    case unit.LuminousIntensity:
        return SI(v.Candela(), "cd"), true
    }
    return Value{}, false
}