scarf 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/scarf/configuration.rb +2 -0
- data/lib/scarf/initial_avatar.rb +15 -3
- data/lib/scarf/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: 0fec22c3e782afe9866babe54d7f61a5e158fd41
|
4
|
+
data.tar.gz: 9d50a573df25036b9b05ba357f0bb6d42d12b982
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09a4f2f5195e0d965d5625c3723311a9d778fa12c31556694e3c3dd2bde2695cec8d10aa52b3f72e500f817f8df16ebe59f9ac247ff8116838d4a0d7792440f3'
|
7
|
+
data.tar.gz: c33a288fd0f4042b04a5b2e62ae67854c31a7a8bb11b7819b7df6aedbb7339e23a8119ec175a1d90c7845d573e395914f73f9a8e6a848c3d88a9213a281881ff
|
data/lib/scarf/configuration.rb
CHANGED
data/lib/scarf/initial_avatar.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
module Scarf
|
2
2
|
class InitialAvatar
|
3
|
-
def initialize(name, font_family: [])
|
3
|
+
def initialize(name, font_family: [], background_shape: nil)
|
4
4
|
@name = name
|
5
|
-
@font_family = font_family.length
|
5
|
+
@font_family = font_family.length.zero? ? Scarf.configuration.font_family : font_family
|
6
|
+
@background_shape = background_shape.nil? ? Scarf.configuration.background_shape : background_shape
|
6
7
|
end
|
7
8
|
|
8
9
|
BACKGROUND = %w(#ff4040 #7f2020 #cc5c33 #734939 #bf9c8f #995200 #4c2900 #f2a200 #ffd580 #332b1a #4c3d00 #ffee00 #b0b386 #64664d #6c8020 #c3d96c #143300 #19bf00 #53a669 #bfffd9 #40ffbf #1a332e #00b3a7 #165955 #00b8e6 #69818c #005ce6 #6086bf #000e66 #202440 #393973 #4700b3 #2b0d33 #aa86b3 #ee00ff #bf60b9 #4d3949 #ff00aa #7f0044 #f20061 #330007 #d96c7b).freeze
|
@@ -10,7 +11,7 @@ module Scarf
|
|
10
11
|
def svg
|
11
12
|
<<~WRAPPER.gsub(/$\s+/, '').strip
|
12
13
|
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 100 100">
|
13
|
-
|
14
|
+
#{background}
|
14
15
|
<text fill="#{foreground_fill}" font-size="50" font-family="#{quoted_fonts}" x="50" y="50" text-anchor="middle" alignment-baseline="central">#{initials}</text>
|
15
16
|
</svg>
|
16
17
|
WRAPPER
|
@@ -18,6 +19,17 @@ module Scarf
|
|
18
19
|
|
19
20
|
private
|
20
21
|
|
22
|
+
def background
|
23
|
+
case(@background_shape)
|
24
|
+
when :rectangle
|
25
|
+
return "<rect width=\"100\" height=\"100\" fill=\"#{background_fill}\" />"
|
26
|
+
when :circle
|
27
|
+
return "<circle cx=\"50\" cy=\"50\" r=\"50\" fill=\"#{background_fill}\" />"
|
28
|
+
else
|
29
|
+
raise "Unknown background_shape #{@background_shape} supplied to Scarf::InitialAvatar"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
21
33
|
# Surround the font name with single quotes if there's a space in the name, and isn't quoted already.
|
22
34
|
def quoted_fonts
|
23
35
|
quoted_fonts = @font_family.map do |font|
|
data/lib/scarf/version.rb
CHANGED