diff --git a/lib/letter_avatar/colors.rb b/lib/letter_avatar/colors.rb index 0cbafcf..d09bdf1 100644 --- a/lib/letter_avatar/colors.rb +++ b/lib/letter_avatar/colors.rb @@ -33,23 +33,17 @@ module LetterAvatar ] def self.for(username) - char = username[0] - char.upcase! + char = username[0].upcase + if /[A-Z]/.match(char) # 65 is 'A' ord idx = char.ord - 65 - return all[idx] - end - - if /[\d]/.match(char) - return all[char.to_i] + COLORS[idx] + elsif /[\d]/.match(char) + COLORS[char.to_i] + else + COLORS[Digest::MD5.hexdigest(username)[0...15].to_i(16) % all.length] end - - all[Digest::MD5.hexdigest(username)[0...15].to_i(16) % all.length] - end - - def self.all - COLORS end end -- libgit2 0.21.0