-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modifies protocols to support external color modules
- Loading branch information
1 parent
4e502e5
commit 05ae1d5
Showing
11 changed files
with
384 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,7 @@ | ||
defmodule Chameleon.Color do | ||
defprotocol Chameleon.Color do | ||
@moduledoc """ | ||
Chameleon.Color | ||
Converts color inputs into supported structs. | ||
Performs the conversions from one color model to another. | ||
""" | ||
|
||
@doc """ | ||
Converts input into valid struct. | ||
## Examples | ||
iex> Chameleon.Color.new(%{hex: "000000"}) | ||
%Chameleon.Hex{hex: "000000"} | ||
iex> Chameleon.Color.new(%{c: 0, m: 0, y: 0, k: 100}) | ||
%Chameleon.Cmyk{c: 0, m: 0, y: 0, k: 100} | ||
""" | ||
@spec new(map()) :: struct() | ||
def new(%{c: c, m: m, y: y, k: k}), do: %Chameleon.Cmyk{c: c, m: m, y: y, k: k} | ||
def new(%{r: r, g: g, b: b}), do: %Chameleon.Rgb{r: r, g: g, b: b} | ||
def new(%{h: h, s: s, l: l}), do: %Chameleon.Hsl{h: h, s: s, l: l} | ||
def new(%{hex: hex}), do: %Chameleon.Hex{hex: hex} | ||
def new(%{pantone: pantone}), do: %Chameleon.Pantone{pantone: pantone} | ||
def new(%{keyword: keyword}), do: %Chameleon.Keyword{keyword: keyword} | ||
def new(_other), do: argument_error() | ||
def new(), do: argument_error() | ||
|
||
defp argument_error do | ||
message = """ | ||
A color argument must be included in one of the following formats: | ||
%{c: 0, m: 0, y: 0, k: 0} | ||
%{r: 0, g: 0, b: 0} | ||
%{h: 0, s: 0, l: 0} | ||
%{hex: "000000"} | ||
%{pantone: "30"} | ||
%{keyword: "black"} | ||
""" | ||
|
||
Mix.raise(message) | ||
end | ||
@spec convert(struct()) :: struct() | ||
def convert(conversion) | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.