Created
August 15, 2013 21:56
-
-
Save bplexico/6245349 to your computer and use it in GitHub Desktop.
ColorGenerator class after refactor
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 generated_color | |
return make_hex(@color.ljust(6, @color)) if (1..2).include?(@color.length) | |
return make_hex(@color.scan(/((.))/).flatten.join) if @color.length == 3 | |
return make_hex(@color.ljust(6, '0')) if (4..5).include?(@color.length) | |
return make_hex(@color[0..5]) if @color.length > 6 | |
return make_hex(@color) | |
end | |
private | |
def make_hex(value) | |
"##{value.downcase}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment