letter_avatar 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/letter_avatar/colors.rb +13 -7
- data/lib/letter_avatar/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97bcbc095f0408ec7d44fca674a71b187fbc9ddd
|
4
|
+
data.tar.gz: 3d62353ec56b3fd0ee710510766e8ad2ca5f7405
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0dcd512bb005824a0c74a75f25e5a624cdaebd5e492f7141836bcbf684c35a7845d3488f6defdf94b3bf3f163b539eca384e46cdb46e22c76f6da2188be1a7e
|
7
|
+
data.tar.gz: d318261498e46bd130863489d143a1f8d74ca670f54f03c4f8309bbf0a85049902064714528b06d84b5075bb76fe5b8de62b1970e0d47f09ab3ac3185d5ed89c
|
data/lib/letter_avatar/colors.rb
CHANGED
@@ -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
|
-
|
20
|
+
google[idx]
|
11
21
|
elsif /[\d]/.match(char)
|
12
|
-
|
22
|
+
google[char.to_i]
|
13
23
|
else
|
14
|
-
|
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
|