mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-24 04:27:59 +01:00
26 lines
564 B
Elixir
26 lines
564 B
Elixir
|
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
|