Documentation
¶
Overview ¶
Package measurement provides value objects related to measurement information.
Package measurement provides value objects related to measurement information.
Package measurement provides value objects related to measurement information.
Package measurement provides value objects related to measurement information.
Package measurement provides value objects related to measurement information.
Package measurement provides value objects related to measurements and units.
Index ¶
- type FileSize
- func (v FileSize) Add(other FileSize) FileSize
- func (v FileSize) Bytes() uint64
- func (v FileSize) Equals(other FileSize) bool
- func (v FileSize) Format(format string) string
- func (v FileSize) Gigabytes() float64
- func (v FileSize) IsEmpty() bool
- func (v FileSize) IsLargerThan(other FileSize) bool
- func (v FileSize) IsSmallerThan(other FileSize) bool
- func (v FileSize) Kilobytes() float64
- func (v FileSize) MarshalJSON() ([]byte, error)
- func (v FileSize) Megabytes() float64
- func (v FileSize) Petabytes() float64
- func (v FileSize) String() string
- func (v FileSize) Subtract(other FileSize) FileSize
- func (v FileSize) Terabytes() float64
- func (v FileSize) ToMap() map[string]interface{}
- func (v FileSize) Validate() error
- type FileSizeUnit
- type MemSize
- func (ms MemSize) Add(other MemSize) MemSize
- func (ms MemSize) Bytes() uint64
- func (ms MemSize) Equals(other MemSize) bool
- func (ms MemSize) Format(format string) string
- func (ms MemSize) Gibibytes() float64
- func (ms MemSize) IsEmpty() bool
- func (ms MemSize) IsLargerThan(other MemSize) bool
- func (ms MemSize) IsSmallerThan(other MemSize) bool
- func (ms MemSize) Kibibytes() float64
- func (ms MemSize) MarshalJSON() ([]byte, error)
- func (ms MemSize) Mebibytes() float64
- func (ms MemSize) Pebibytes() float64
- func (ms MemSize) String() string
- func (ms MemSize) Subtract(other MemSize) MemSize
- func (ms MemSize) Tebibytes() float64
- func (ms MemSize) ToMap() map[string]interface{}
- func (ms MemSize) Validate() error
- type MemSizeUnit
- type Money
- func (v Money) Abs() Money
- func (v Money) Add(other Money) (Money, error)
- func (v Money) Amount() decimal.Decimal
- func (v Money) AmountInCents() int64
- func (v Money) Currency() string
- func (v Money) Divide(divisor decimal.Decimal) (Money, error)
- func (v Money) Equals(other Money) bool
- func (v Money) IsEmpty() bool
- func (v Money) IsGreaterThan(other Money) (bool, error)
- func (v Money) IsLessThan(other Money) (bool, error)
- func (v Money) IsNegative() bool
- func (v Money) IsPositive() bool
- func (v Money) MarshalJSON() ([]byte, error)
- func (v Money) Multiply(factor decimal.Decimal) Money
- func (v Money) Negate() Money
- func (v Money) String() string
- func (v Money) Subtract(other Money) (Money, error)
- func (v Money) ToMap() map[string]interface{}
- func (v Money) Validate() error
- type Percentage
- func (v Percentage) Add(other Percentage) (Percentage, error)
- func (v Percentage) AsDecimal() float64
- func (v Percentage) Equals(other Percentage) bool
- func (v Percentage) Inverse() (Percentage, error)
- func (v Percentage) IsEmpty() bool
- func (v Percentage) MarshalJSON() ([]byte, error)
- func (v Percentage) Of(value float64) float64
- func (v Percentage) String() string
- func (v Percentage) Subtract(other Percentage) (Percentage, error)
- func (v Percentage) ToMap() map[string]interface{}
- func (v Percentage) Validate() error
- func (v Percentage) Value() float64
- type Rating
- func (v Rating) Equals(other Rating) bool
- func (v Rating) Format(format string) string
- func (v Rating) IsEmpty() bool
- func (v Rating) IsHigher(other Rating) bool
- func (v Rating) IsLower(other Rating) bool
- func (v Rating) MarshalJSON() ([]byte, error)
- func (v Rating) MaxValue() float64
- func (v Rating) Normalized() float64
- func (v Rating) Percentage() float64
- func (v Rating) Stars() string
- func (v Rating) String() string
- func (v Rating) ToMap() map[string]interface{}
- func (v Rating) ToScale(newMaxValue float64) (Rating, error)
- func (v Rating) Validate() error
- func (v Rating) Value() float64
- type Temperature
- func (t Temperature) Add(other Temperature) Temperature
- func (t Temperature) CompareTo(other Temperature) int
- func (t Temperature) Equals(other Temperature) bool
- func (t Temperature) Format(format string) string
- func (t Temperature) IsBoiling() bool
- func (t Temperature) IsEmpty() bool
- func (t Temperature) IsFreezing() bool
- func (t Temperature) String() string
- func (t Temperature) Subtract(other Temperature) (Temperature, error)
- func (t Temperature) ToCelsius() Temperature
- func (t Temperature) ToFahrenheit() Temperature
- func (t Temperature) ToKelvin() Temperature
- func (t Temperature) Unit() TemperatureUnit
- func (t Temperature) Validate() error
- func (t Temperature) Value() float64
- type TemperatureUnit
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FileSize ¶
type FileSize struct {
base.BaseStructValueObject
// contains filtered or unexported fields
}
FileSize represents a file size value object that uses base 10 decimal values in accordance with the International System of Units (SI Units). This is the standard for file sizes in most contexts, where 1 KB = 1000 bytes, 1 MB = 1000 KB, etc., as opposed to the binary-based units used for memory sizes.
func NewFileSize ¶
func NewFileSize(value float64, unit FileSizeUnit) (FileSize, error)
NewFileSize creates a new FileSize with validation Uses base 10 decimal values in accordance with the International System of Units (SI Units), where 1 KB = 1000 bytes, 1 MB = 1000 KB, etc.
func NewFileSizeFromBytes ¶
NewFileSizeFromBytes creates a new FileSize directly from bytes The resulting FileSize will use base 10 decimal values in accordance with the International System of Units (SI Units) for all conversions and formatting.
func ParseFileSize ¶
ParseFileSize creates a new FileSize from a string The parsed value will use base 10 decimal values in accordance with the International System of Units (SI Units), where 1 KB = 1000 bytes, 1 MB = 1000 KB, etc.
func (FileSize) Format ¶
Format returns the file size in the specified format Format options: - "B": Always in bytes - "KB": Always in kilobytes (base 10, ISO standard) - "MB": Always in megabytes (base 10, ISO standard) - "GB": Always in gigabytes (base 10, ISO standard) - "TB": Always in terabytes (base 10, ISO standard) - "PB": Always in petabytes (base 10, ISO standard) - "auto": Uses the most appropriate unit for readability (base 10, ISO standard) - "binary": Uses binary prefixes (KiB, MiB, GiB, etc.) - for compatibility only
func (FileSize) IsLargerThan ¶
IsLargerThan checks if this FileSize is larger than another FileSize
func (FileSize) IsSmallerThan ¶
IsSmallerThan checks if this FileSize is smaller than another FileSize
func (FileSize) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface
func (FileSize) String ¶
String returns the string representation of the FileSize Uses the most appropriate unit for readability
func (FileSize) Subtract ¶
Subtract subtracts another FileSize and returns a new FileSize If the result would be negative, it returns zero
type FileSizeUnit ¶
type FileSizeUnit string
FileSizeUnit represents a file size unit (using base 10 decimal values per ISO standards)
const ( // FileSizeBytes unit (B) FileSizeBytes FileSizeUnit = "B" // Kilobytes unit (KB) - 10^3 bytes Kilobytes FileSizeUnit = "KB" // Megabytes unit (MB) - 10^6 bytes Megabytes FileSizeUnit = "MB" // Gigabytes unit (GB) - 10^9 bytes Gigabytes FileSizeUnit = "GB" // Terabytes unit (TB) - 10^12 bytes Terabytes FileSizeUnit = "TB" // Petabytes unit (PB) - 10^15 bytes Petabytes FileSizeUnit = "PB" )
type MemSize ¶
type MemSize struct {
base.BaseStructValueObject
// contains filtered or unexported fields
}
MemSize represents a memory size value object using base 2 binary values This is specifically for computer memory measurements, not file sizes.
func NewMemSize ¶
func NewMemSize(value float64, unit MemSizeUnit) (MemSize, error)
NewMemSize creates a new MemSize with validation
func ParseMemSize ¶
ParseMemSize creates a new MemSize from a string
func (MemSize) Format ¶
Format returns the memory size in the specified format Format options: - "B": Always in bytes - "KiB": Always in kibibytes - "MiB": Always in mebibytes - "GiB": Always in gibibytes - "TiB": Always in tebibytes - "PiB": Always in pebibytes - "auto": Uses the most appropriate unit for readability
func (MemSize) IsLargerThan ¶
IsLargerThan checks if this MemSize is larger than another MemSize
func (MemSize) IsSmallerThan ¶
IsSmallerThan checks if this MemSize is smaller than another MemSize
func (MemSize) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface
func (MemSize) String ¶
String returns the string representation of the MemSize Uses the most appropriate unit for readability with binary (base 2) units
func (MemSize) Subtract ¶
Subtract subtracts another MemSize and returns a new MemSize If the result would be negative, it returns zero
type MemSizeUnit ¶
type MemSizeUnit string
MemSizeUnit represents a memory size unit (using base 2 binary values)
const ( // Bytes unit (B) Bytes MemSizeUnit = "B" // Kibibytes unit (KiB) - 2^10 bytes Kibibytes MemSizeUnit = "KiB" // Mebibytes unit (MiB) - 2^20 bytes Mebibytes MemSizeUnit = "MiB" // Gibibytes unit (GiB) - 2^30 bytes Gibibytes MemSizeUnit = "GiB" // Tebibytes unit (TiB) - 2^40 bytes Tebibytes MemSizeUnit = "TiB" // Pebibytes unit (PiB) - 2^50 bytes Pebibytes MemSizeUnit = "PiB" )
type Money ¶
type Money struct {
base.BaseStructValueObject
// contains filtered or unexported fields
}
Money represents a monetary value object with amount and currency
func NewMoneyFromFloat64 ¶
NewMoneyFromFloat64 creates a new Money with validation from a float64 amount
func NewMoneyFromString ¶
NewMoneyFromString creates a new Money with validation from a string amount This is more precise than using a float64 for monetary values
func (Money) Add ¶
Add adds another Money value and returns a new Money Both Money values must have the same currency
func (Money) AmountInCents ¶
AmountInCents returns the amount in the smallest currency unit (e.g., cents)
func (Money) Divide ¶
Divide divides the money amount by a divisor (e.g., for splitting payments) and returns a new Money object Returns an error if the divisor is zero
func (Money) IsGreaterThan ¶
IsGreaterThan checks if the Money amount is greater than another Money amount Returns an error if the currencies are different
func (Money) IsLessThan ¶
IsLessThan checks if the Money amount is less than another Money amount Returns an error if the currencies are different
func (Money) IsNegative ¶
IsNegative checks if the Money amount is negative
func (Money) IsPositive ¶
IsPositive checks if the Money amount is positive
func (Money) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface
func (Money) Multiply ¶
Multiply multiplies the money amount by a factor (e.g., for calculating interest) and returns a new Money object
func (Money) Subtract ¶
Subtract subtracts another Money value and returns a new Money Both Money values must have the same currency
type Percentage ¶
type Percentage struct {
base.BaseStructValueObject
// contains filtered or unexported fields
}
Percentage represents a percentage value object
func NewPercentage ¶
func NewPercentage(value float64) (Percentage, error)
NewPercentage creates a new Percentage with validation
func ParsePercentage ¶
func ParsePercentage(s string) (Percentage, error)
ParsePercentage creates a new Percentage from a string
func (Percentage) Add ¶
func (v Percentage) Add(other Percentage) (Percentage, error)
Add adds another percentage and returns a new Percentage The result is capped at 100%
func (Percentage) AsDecimal ¶
func (v Percentage) AsDecimal() float64
AsDecimal returns the percentage as a decimal (e.g., 75% -> 0.75)
func (Percentage) Equals ¶
func (v Percentage) Equals(other Percentage) bool
Equals checks if two Percentages are equal
func (Percentage) Inverse ¶
func (v Percentage) Inverse() (Percentage, error)
Inverse returns the inverse percentage (100% - p)
func (Percentage) IsEmpty ¶
func (v Percentage) IsEmpty() bool
IsEmpty checks if the Percentage is empty (zero value)
func (Percentage) MarshalJSON ¶
func (v Percentage) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface
func (Percentage) Of ¶
func (v Percentage) Of(value float64) float64
Of calculates the percentage of a given value For example: 25% of 200 = 50
func (Percentage) String ¶
func (v Percentage) String() string
String returns the string representation of the Percentage
func (Percentage) Subtract ¶
func (v Percentage) Subtract(other Percentage) (Percentage, error)
Subtract subtracts another percentage and returns a new Percentage The result is floored at 0%
func (Percentage) ToMap ¶
func (v Percentage) ToMap() map[string]interface{}
ToMap converts the Percentage to a map[string]interface{}
func (Percentage) Validate ¶
func (v Percentage) Validate() error
Validate checks if the Percentage is valid
type Rating ¶
type Rating struct {
base.BaseStructValueObject
// contains filtered or unexported fields
}
Rating represents a rating value object (e.g., 1-5 stars)
func ParseRating ¶
ParseRating creates a new Rating from a string Formats supported: - "4" (assumes max value of 5) - "4/5" (explicit max value) - "8/10" (explicit max value)
func (Rating) Format ¶
Format returns the rating in the specified format Format options: - "decimal": "4.5/5.0" - "percentage": "90%" - "stars": "★★★★½" - "fraction": "9/10"
func (Rating) IsHigher ¶
IsHigher checks if this rating is higher than another rating This compares the normalized values to handle different scales
func (Rating) IsLower ¶
IsLower checks if this rating is lower than another rating This compares the normalized values to handle different scales
func (Rating) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface
func (Rating) Normalized ¶
Normalized returns the rating normalized to a 0-1 scale
func (Rating) Percentage ¶
Percentage returns the rating as a percentage of the maximum value
func (Rating) Stars ¶
Stars returns the rating as a string of stars (★) and empty stars (☆) For example, a rating of 3.5/5 would return "★★★½☆"
type Temperature ¶
type Temperature struct {
// contains filtered or unexported fields
}
Temperature represents a temperature value object
func NewTemperature ¶
func NewTemperature(value float64, unit TemperatureUnit) (Temperature, error)
NewTemperature creates a new Temperature with validation
func ParseTemperature ¶
func ParseTemperature(s string) (Temperature, error)
ParseTemperature creates a new Temperature from a string
func (Temperature) Add ¶
func (t Temperature) Add(other Temperature) Temperature
Add adds another temperature and returns a new Temperature
func (Temperature) CompareTo ¶
func (t Temperature) CompareTo(other Temperature) int
CompareTo compares this temperature with another and returns: -1 if this < other
0 if this == other 1 if this > other
func (Temperature) Equals ¶
func (t Temperature) Equals(other Temperature) bool
Equals checks if two Temperatures are equal This compares the actual temperature values, not just the raw values and units
func (Temperature) Format ¶
func (t Temperature) Format(format string) string
Format returns the temperature in the specified format Format options: - "short": "25°C" - "long": "25 degrees Celsius" - "scientific": "298.15K"
func (Temperature) IsBoiling ¶
func (t Temperature) IsBoiling() bool
IsBoiling checks if the temperature is at or above the boiling point of water
func (Temperature) IsEmpty ¶
func (t Temperature) IsEmpty() bool
IsEmpty checks if the Temperature is empty (zero value)
func (Temperature) IsFreezing ¶
func (t Temperature) IsFreezing() bool
IsFreezing checks if the temperature is at or below the freezing point of water
func (Temperature) String ¶
func (t Temperature) String() string
String returns the string representation of the Temperature
func (Temperature) Subtract ¶
func (t Temperature) Subtract(other Temperature) (Temperature, error)
Subtract subtracts another temperature and returns a new Temperature
func (Temperature) ToCelsius ¶
func (t Temperature) ToCelsius() Temperature
ToCelsius converts the temperature to Celsius
func (Temperature) ToFahrenheit ¶
func (t Temperature) ToFahrenheit() Temperature
ToFahrenheit converts the temperature to Fahrenheit
func (Temperature) ToKelvin ¶
func (t Temperature) ToKelvin() Temperature
ToKelvin converts the temperature to Kelvin
func (Temperature) Unit ¶
func (t Temperature) Unit() TemperatureUnit
Unit returns the temperature unit
func (Temperature) Validate ¶
func (t Temperature) Validate() error
Validate checks if the Temperature is valid
type TemperatureUnit ¶
type TemperatureUnit string
TemperatureUnit represents a temperature unit
const ( // Celsius temperature unit (°C) Celsius TemperatureUnit = "C" // Fahrenheit temperature unit (°F) Fahrenheit TemperatureUnit = "F" // Kelvin temperature unit (K) Kelvin TemperatureUnit = "K" )