Commit 4b74fdab648bc6400c0e4b598de5df23ff5659c1
1 parent
9f604744
Exists in
master
Colors simplified, .all removed
Showing
1 changed file
with
7 additions
and
13 deletions
Show diff stats
lib/letter_avatar/colors.rb
@@ -33,23 +33,17 @@ module LetterAvatar | @@ -33,23 +33,17 @@ module LetterAvatar | ||
33 | ] | 33 | ] |
34 | 34 | ||
35 | def self.for(username) | 35 | def self.for(username) |
36 | - char = username[0] | ||
37 | - char.upcase! | 36 | + char = username[0].upcase |
37 | + | ||
38 | if /[A-Z]/.match(char) | 38 | if /[A-Z]/.match(char) |
39 | # 65 is 'A' ord | 39 | # 65 is 'A' ord |
40 | idx = char.ord - 65 | 40 | idx = char.ord - 65 |
41 | - return all[idx] | ||
42 | - end | ||
43 | - | ||
44 | - if /[\d]/.match(char) | ||
45 | - return all[char.to_i] | 41 | + COLORS[idx] |
42 | + elsif /[\d]/.match(char) | ||
43 | + COLORS[char.to_i] | ||
44 | + else | ||
45 | + COLORS[Digest::MD5.hexdigest(username)[0...15].to_i(16) % all.length] | ||
46 | end | 46 | end |
47 | - | ||
48 | - all[Digest::MD5.hexdigest(username)[0...15].to_i(16) % all.length] | ||
49 | - end | ||
50 | - | ||
51 | - def self.all | ||
52 | - COLORS | ||
53 | end | 47 | end |
54 | 48 | ||
55 | end | 49 | end |