bool.go
bool.go - Overview
-
Overview This file defines a
boolFormatter
struct and its associated methods to format float64 values into boolean-like string representations based on the provided unit. -
Detailed Documentation
boolFormatter
- Purpose: Represents a formatter that converts float64 values to boolean-like strings.
- Parameters: None
- Returns: None
NewBoolFormatter
- Purpose: Creates a new instance of
boolFormatter
. - Parameters: None
- Returns:
Formatter
: A pointer to a newboolFormatter
instance.
(*boolFormatter) Name
- Purpose: Returns the name of the formatter.
- Parameters: None
- Returns:
string
: The string "bool".
toBool
- Purpose: Converts a float64 value to a boolean string representation ("true" or "false").
- Parameters:
value
(float64): The value to convert.
- Returns:
string
: "false" if the value is 0, "true" otherwise.
toBoolYesNo
- Purpose: Converts a float64 value to a "yes" or "no" string representation.
- Parameters:
value
(float64): The value to convert.
- Returns:
string
: "no" if the value is 0, "yes" otherwise.
toBoolOnOff
- Purpose: Converts a float64 value to an "on" or "off" string representation.
- Parameters:
value
(float64): The value to convert.
- Returns:
string
: "off" if the value is 0, "on" otherwise.
(f *boolFormatter) Format
- Purpose: Formats a float64 value to a boolean-like string based on the provided unit.
- Parameters:
value
(float64): The value to format.unit
(string): The unit specifying the desired boolean representation ("bool", "bool_yes_no", or "bool_on_off").
- Returns:
string
: The formatted string representation of the value. Returns the original value as a string if the unit is not recognized.
-
Code Examples None
-
Clarity and Accuracy The documentation is derived directly from the code.
-
Markdown & MDX Perfection The markdown has been validated.
-
Edge Cases To Avoid Breaking MDX All potential MDX breaking elements have been handled.
-
Getting Started Relevance Include in Getting Started: NO