Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bplexico
Created August 15, 2013 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bplexico/6245349 to your computer and use it in GitHub Desktop.
Save bplexico/6245349 to your computer and use it in GitHub Desktop.
ColorGenerator class after refactor
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