scarf 0.2.6 → 0.3.0
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 +8 -0
- data/lib/scarf/initial_avatar.rb +7 -6
- data/lib/scarf/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48f39ad7df57e0c4e3ec6dd7783c3e7f7c2f01476b57506919db2cd7b46eb348
|
4
|
+
data.tar.gz: 4b874107a0b23d05ee5a5cc348ae1d73d3691d08a35de25bae1aa250014ddb24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15becc41b860df0959b2474733b32fdc6d009f4cfc91cbf8f103fcdfa42f6ac0fb724690688abdbcbdfdc0c74fe58da8c3f4e674d59f3b4836a8d9e131e6abbb
|
7
|
+
data.tar.gz: 412ba858472718fa74d335a73be41c2c36a1710e353d71482b448731bfa45e18954994c33b569dd82e89e3f7624a717f01aa1e4a04da82fd7e4bc5cd32fe0b40
|
data/lib/scarf/configuration.rb
CHANGED
@@ -1,12 +1,20 @@
|
|
1
1
|
module Scarf
|
2
2
|
# Store configuration for this gem.
|
3
3
|
class Configuration
|
4
|
+
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
|
4
5
|
attr_accessor :font_family
|
6
|
+
attr_accessor :font_weight
|
7
|
+
attr_accessor :font_size
|
5
8
|
attr_accessor :background_shape
|
9
|
+
attr_accessor :background_colors
|
6
10
|
|
7
11
|
def initialize
|
8
12
|
@font_family = %w(sans-serif)
|
13
|
+
# normal | bold | bolder | lighter | <number>
|
14
|
+
@font_weight = 'normal'
|
15
|
+
@font_size = '42'
|
9
16
|
@background_shape = :circle
|
17
|
+
@background_colors = BACKGROUND
|
10
18
|
end
|
11
19
|
end
|
12
20
|
end
|
data/lib/scarf/initial_avatar.rb
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
module Scarf
|
2
2
|
class InitialAvatar
|
3
|
-
def initialize(name, font_family: [], background_shape: nil)
|
3
|
+
def initialize(name, font_family: [], font_weight: nil, font_size: nil, background_shape: nil, background_colors: [])
|
4
4
|
@name = name
|
5
5
|
@font_family = font_family.length.zero? ? Scarf.configuration.font_family : font_family
|
6
|
+
@font_weight = font_weight.nil? ? Scarf.configuration.font_weight : font_weight
|
7
|
+
@font_size = font_size.nil? ? Scarf.configuration.font_size : font_size
|
6
8
|
@background_shape = background_shape.nil? ? Scarf.configuration.background_shape : background_shape
|
9
|
+
@background_colors = background_colors.length.zero? ? Scarf.configuration.background_colors : background_colors
|
7
10
|
end
|
8
11
|
|
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
|
-
|
11
12
|
def svg
|
12
13
|
<<~WRAPPER.gsub(/$\s+/, '').strip
|
13
14
|
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 100 100">
|
14
15
|
#{background}
|
15
|
-
<text fill="#{foreground_fill}" font-size="
|
16
|
+
<text fill="#{foreground_fill}" font-size="#{@font_size}" font-weight="#{@font_weight}" font-family="#{quoted_fonts}" x="50" y="54" text-anchor="middle" dominant-baseline="middle" alignment-baseline="middle">#{initials}</text>
|
16
17
|
</svg>
|
17
18
|
WRAPPER
|
18
19
|
end
|
@@ -47,8 +48,8 @@ module Scarf
|
|
47
48
|
def background_fill
|
48
49
|
@background_fill ||= begin
|
49
50
|
digest = "0.#{Digest::MD5.hexdigest(@name).to_i(16).to_s}".to_f
|
50
|
-
index = (digest * (
|
51
|
-
|
51
|
+
index = (digest * (@background_colors.length - 1)).round
|
52
|
+
@background_colors[index]
|
52
53
|
end
|
53
54
|
end
|
54
55
|
|
data/lib/scarf/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scarf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hari Gopal
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-12-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -67,7 +67,8 @@ dependencies:
|
|
67
67
|
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '2.0'
|
70
|
-
description: A Ruby library for generating initial avatars and identicons
|
70
|
+
description: A Ruby library for generating initial avatars and identicons, with configurable
|
71
|
+
fonts, colors, and shapes.
|
71
72
|
email: mail@harigopal.in
|
72
73
|
executables: []
|
73
74
|
extensions: []
|
@@ -99,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
100
|
- !ruby/object:Gem::Version
|
100
101
|
version: '0'
|
101
102
|
requirements: []
|
102
|
-
rubygems_version: 3.
|
103
|
+
rubygems_version: 3.2.32
|
103
104
|
signing_key:
|
104
105
|
specification_version: 4
|
105
106
|
summary: A Ruby library for generating initial avatars and identicons.
|