int_support v0.1.0 IntSupport View Source

A port of Rail's ActiveSupport Integer extensions.

Link to this section Summary

Functions

Produce a string representation of a number as a human-readable number of bytes

Returns the number of bytes from passed number of gigabytes.

Returns the number of bytes from passed number of kilobytes.

Returns the number of bytes from passed number of megabytes.

Returns a string of the passed integer with the associated ordinal appended.

Returns the number of bytes from passed number of terabytes.

Converts an integer into a phone number formatted string.

Link to this section Functions

Produce a string representation of a number as a human-readable number of bytes:

Examples

iex> IntSupport.bytes_to_human(123)
"123 Bytes"
iex> IntSupport.bytes_to_human(1234)
"1.21 KB"
iex> IntSupport.bytes_to_human(1234567)
"1.18 MB"
iex> IntSupport.bytes_to_human(1234567890)
"1.15 GB"
iex> IntSupport.bytes_to_human(1234567890123)
"1.12 TB"

Returns the number of bytes from passed number of gigabytes.

Examples

iex> IntSupport.gigabytes(3)
3221225472

Returns the number of bytes from passed number of kilobytes.

Examples

iex> IntSupport.kilobytes(2)
2048

Returns the number of bytes from passed number of megabytes.

Examples

iex> IntSupport.megabytes(3)
3145728
Link to this function

ordinalize(int)

View Source (since 0.1.0)

Returns a string of the passed integer with the associated ordinal appended.

Examples

iex> IntSupport.ordinalize(1)
"1st"
iex> IntSupport.ordinalize(2)
"2nd"
iex> IntSupport.ordinalize(52)
"52nd"
iex> IntSupport.ordinalize(53)
"53rd"
iex> IntSupport.ordinalize(2009)
"2009th"
iex> IntSupport.ordinalize(-21)
"-21st"
iex> IntSupport.ordinalize(-134)
"-134th"

Returns the number of bytes from passed number of terabytes.

Examples

iex> IntSupport.terabytes(4)
4398046511104

Converts an integer into a phone number formatted string.

Examples

iex> IntSupport.to_phone_number(5551234)
"555-1234"
iex> IntSupport.to_phone_number(1235554444)
"(123) 555-4444"