barakyo / color_utils

14 stars 11 forks source link

Failure when using lower case hex strings #4

Open benrom opened 8 years ago

benrom commented 8 years ago
iex > ColorUtils.hex_to_rgb("#C8C8C8")
%ColorUtils.RGB{blue: 200.0, green: 200.0, red: 200.0}

iex > ColorUtils.hex_to_rgb("#c8c8c8")
** (ArithmeticError) bad argument in arithmetic expression
             lib/color_utils.ex:260: anonymous fn/1 in ColorUtils.hex_to_decimal/1
    (elixir) lib/enum.ex:1184: Enum."-map/2-lists^map/1-0-"/2
             lib/color_utils.ex:256: ColorUtils.hex_to_decimal/1
             lib/color_utils.ex:65: ColorUtils.hex_to_rgb/1
benrom commented 8 years ago

Also fails with shorter hex values like #ccc (valid in html, equals to #cccccc):

iex> ColorUtils.hex_to_rgb("#ccc")
** (FunctionClauseError) no function clause matching in ColorUtils.hex_to_rgb/1
    lib/color_utils.ex:59: ColorUtils.hex_to_rgb("ccc")
denispeplin commented 7 years ago

@benrom please check if #5 works for you.

benrom commented 7 years ago

Success!

iex(1)> ColorUtils.hex_to_rgb("#C8C8C8")
%ColorUtils.RGB{blue: 200.0, green: 200.0, red: 200.0}
iex(2)> ColorUtils.hex_to_rgb("#c8c8c8")
%ColorUtils.RGB{blue: 200.0, green: 200.0, red: 200.0}
iex(3)> ColorUtils.hex_to_rgb("#ccc")
%ColorUtils.RGB{blue: 204.0, green: 204.0, red: 204.0}
benrom commented 7 years ago

I forgot to close this issue.. Would it be possible to get a new hex release soon that includes all the latest fixes?

benrom commented 7 years ago

Actually that PR has not been merged yet... reopening