Commit b5ecfde28485cfd9acd16835c0275a4a3fdff763
1 parent
b057e527
Exists in
master
another colos palette option fix
Showing
2 changed files
with
14 additions
and
8 deletions
Show diff stats
lib/letter_avatar/colors.rb
... | ... | @@ -2,23 +2,29 @@ module LetterAvatar |
2 | 2 | module Colors |
3 | 3 | |
4 | 4 | def self.for(username) |
5 | + public_send("with_#{LetterAvatar.colors_palette}", username) rescue with_google(username) | |
6 | + end | |
7 | + | |
8 | + def self.with_iwanthue(username) | |
9 | + iwanthue[ | |
10 | + Digest::MD5.hexdigest(username)[0...15].to_i(16) % iwanthue.length | |
11 | + ] | |
12 | + end | |
13 | + | |
14 | + def self.with_google(username) | |
5 | 15 | char = username[0].upcase |
6 | 16 | |
7 | 17 | if /[A-Z]/.match(char) |
8 | 18 | # 65 is 'A' ord |
9 | 19 | idx = char.ord - 65 |
10 | - COLORS[idx] | |
20 | + google[idx] | |
11 | 21 | elsif /[\d]/.match(char) |
12 | - COLORS[char.to_i] | |
22 | + google[char.to_i] | |
13 | 23 | else |
14 | - COLORS[Digest::MD5.hexdigest(username)[0...15].to_i(16) % COLORS.length] | |
24 | + google[Digest::MD5.hexdigest(username)[0...15].to_i(16) % google.length] | |
15 | 25 | end |
16 | 26 | end |
17 | 27 | |
18 | - def self.colors | |
19 | - public_send(LetterAvatar.colors_palette) rescue google | |
20 | - end | |
21 | - | |
22 | 28 | |
23 | 29 | # Colors form Google Inbox |
24 | 30 | # https://inbox.google.com | ... | ... |
lib/letter_avatar/version.rb