mpd v0.1.0 Mpd.Utils View Source

Link to this section Summary

Functions

Convert an integer value to boolean. MPD uses 1 as true and it gets read as a string from the output.

Formats a time in second to "MM:SS" format.

Includes logging helpers to do logging using module name as namespace.

Checks if two strings are insensitively like. Since it does a to_string/1 it can handles almost any stringable format.

Parses a float from a string in safe way returning a 0.0 in the case of a failure

Parses an int from a string in safe way returning a 0 in the case of a failure

Link to this section Functions

Specs

boolean_int(binary()) :: boolean()

Convert an integer value to boolean. MPD uses 1 as true and it gets read as a string from the output.

Specs

format_time(number()) :: binary()

Formats a time in second to "MM:SS" format.

Includes logging helpers to do logging using module name as namespace.

Link to this function

string_like?(first, second)

View Source

Specs

string_like?(any(), any()) :: boolean()

Checks if two strings are insensitively like. Since it does a to_string/1 it can handles almost any stringable format.

It also support list to compare against as a second parameter

Examples

iex> str = "Primus - Too many puppies"
"Primus - Too many puppies"
iex> Mpd.Utils.string_like?(str, "pri")
true
iex> Mpd.Utils.string_like?(str, "pup")
true
iex> Mpd.Utils.string_like?("Primus - Too many puppies", ["IAM", "Primus"])
true
iex> Mpd.Utils.string_like?("Primus - Too many puppies", ["Pink Floyd"])
false

Specs

to_float(binary()) :: float()

Parses a float from a string in safe way returning a 0.0 in the case of a failure

Specs

to_int(binary()) :: integer()

Parses an int from a string in safe way returning a 0 in the case of a failure