Last active
December 21, 2015 03:49
-
-
Save bplexico/6245288 to your computer and use it in GitHub Desktop.
method moved to class
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
class ColorGenerator | |
def initialize(color) | |
@color = color | |
end | |
def get_hex(color) | |
case | |
when color.length == 1 | |
generated_color = color * 6 | |
when color.length == 2 | |
generated_color = color * 3 | |
when color.length == 3 | |
generated_color = (color[0] * 2) + (color[1] * 2) + (color[2] * 2) | |
when color.length < 6 && color.length > 3 | |
generated_color = color + ("0" * (6 - color.length)) | |
when color.length > 6 | |
generated_color = color[0..5] | |
else | |
generated_color = color | |
end | |
return "##{generated_color}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment