Documentation ¶
Overview ¶
Package units provides measurement systems, and unit conversion.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertParagraph ¶
ConvertParagraph converts the paragraph to the desired System.
func ConvertSentence ¶
ConvertSentence converts the sentence to the desired System.
func ReplaceDecimalFractions ¶
ReplaceDecimalFractions converts the decimals in a string to fractions.
func ReplaceVulgarFractions ¶
ReplaceVulgarFractions replaces vulgar fractions in a string to decimal ones.
Types ¶
type Measurement ¶
Measurement represents a physical measurement consisting of a quantity and a unit.
func NewMeasurement ¶
func NewMeasurement(quantity float64, unit string) (Measurement, error)
NewMeasurement creates a Measurement from a quantity of type int or float64 and a unit. The creation fails when the unit is invalid.
func NewMeasurementFromString ¶
func NewMeasurementFromString(s string) (Measurement, error)
NewMeasurementFromString creates a Measurement from a string.
func (Measurement) Convert ¶
func (m Measurement) Convert(to Unit) (Measurement, error)
Convert converts the measurement to the desired unit.
func (Measurement) Scale ¶
func (m Measurement) Scale(multiplier float64) Measurement
Scale scales the measurement by the given multiplier.
func (Measurement) String ¶
func (m Measurement) String() string
String represents the Measurement as a string.
type System ¶
type System string
System is a type alias for a measurement system.
const ( ImperialSystem System = "imperial" InvalidSystem System = "invalid" MetricSystem System = "metric" )
These constants enumerate all possible measurement systems.
func DetectMeasurementSystem ¶
DetectMeasurementSystem determines the System used in the text.
type TokenizedIngredient ¶
type TokenizedIngredient struct { Ingredients []string Measurement Measurement }
TokenizedIngredient holds tokenized ingredients and a Measurement.
func NewTokenizedIngredientFromText ¶
func NewTokenizedIngredientFromText(sentence string) TokenizedIngredient
NewTokenizedIngredientFromText creates a TokenizedIngredient from a sentence.
type Unit ¶
type Unit int
Unit type is a string alias representing a unit.