MikrotikApi.Normalize (mikrotik_api v0.3.4)

View Source

Optional normalization helpers for turning RouterOS string fields into typed values.

NOTE: Core helpers do not depend on this module. Exporters may choose to use these utilities when building metrics.

Summary

Functions

Convert common string booleans to true/false. Accepts: true/false, "true"/"false", "yes"/"no", "enabled"/"disabled". Returns boolean or the original value if not matched.

Parse rates like "877 Mbps" or "54 Mbps" into integer Mbps. Returns integer Mbps or original value if the unit doesn't match.

Convert float-looking strings (e.g., "-3.14", "1.0e3") to floats. Returns float or original value if parsing fails.

Convert numeric-looking strings (e.g., "-64", "1500") to integers. Returns integer or original value if parsing fails.

Functions

normalize_bool(v)

@spec normalize_bool(term()) :: boolean() | term()

Convert common string booleans to true/false. Accepts: true/false, "true"/"false", "yes"/"no", "enabled"/"disabled". Returns boolean or the original value if not matched.

parse_rate_mbps(v)

@spec parse_rate_mbps(term()) :: integer() | term()

Parse rates like "877 Mbps" or "54 Mbps" into integer Mbps. Returns integer Mbps or original value if the unit doesn't match.

to_float(v)

@spec to_float(term()) :: float() | term()

Convert float-looking strings (e.g., "-3.14", "1.0e3") to floats. Returns float or original value if parsing fails.

to_int(v)

@spec to_int(term()) :: integer() | term()

Convert numeric-looking strings (e.g., "-64", "1500") to integers. Returns integer or original value if parsing fails.