philomena/lib/search/helpers.ex

26 lines
564 B
Elixir
Raw Normal View History

2019-11-02 19:34:25 +01:00
defmodule Search.Helpers do
# Apparently, it's too hard for the standard library to to parse a number
# as a float if it doesn't contain a decimal point. WTF
def to_number(term) do
{float_val, _} = :string.to_float(term)
{int_val, _} = :string.to_integer(term)
cond do
is_float(float_val) ->
float_val
is_integer(int_val) ->
int_val
end
end
def to_int(term) do
{int, _} = :string.to_integer(term)
int
end
def range([center, deviation]) do
[center - deviation, center + deviation]
end
end