initials 0.4.0 → 0.4.1
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/initials/svg.rb +8 -3
- data/lib/initials/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2967ee83aead20c8869af14e57d6a573298453f296187a64b8f2480e626e1d6c
|
4
|
+
data.tar.gz: 16577212cb755c24cd7d824c9dd1dd2f4be699173ffdf0d09edbc2c97228a070
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 894c0090dd2b77e3da58894a8350a4309d49bb2c88ef6d57ebb95b140e2bacd2b5a39887b600edc1bfeac967994b9ef34b5575e9d9273efc20a05d0a343b48a0
|
7
|
+
data.tar.gz: ed742e7bc42d1edc4528e28cc553b4c8afa0399ec0dc84d521eca0fc15a0423e9f9cd31fa206b4bc5a6ad2a4b52606b4ed4317141eafffd47f1871b42bd4bd7f
|
data/lib/initials/svg.rb
CHANGED
@@ -5,17 +5,20 @@ module Initials
|
|
5
5
|
attr_reader :name, :colors, :limit, :shape, :size
|
6
6
|
|
7
7
|
def initialize(name, colors: 12, limit: 3, shape: :circle, size: 32)
|
8
|
-
@name = name
|
8
|
+
@name = name.to_s.strip
|
9
9
|
@colors = colors
|
10
10
|
@limit = limit
|
11
11
|
@shape = shape
|
12
12
|
@size = size
|
13
13
|
|
14
|
-
raise Initials::Error.new("Name is not a string or empty.") unless (name.respond_to?(:to_s) && name.to_s.length > 0)
|
15
14
|
raise Initials::Error.new("Colors must be a divider of 360 e.g. 24 but not 16.") unless valid_colors?
|
16
15
|
raise Initials::Error.new("Size is not a positive integer.") unless valid_size?
|
17
16
|
end
|
18
17
|
|
18
|
+
def name
|
19
|
+
@name.empty? ? "?" : @name
|
20
|
+
end
|
21
|
+
|
19
22
|
def to_s
|
20
23
|
svg = [
|
21
24
|
"<svg width='#{size}' height='#{size}'>",
|
@@ -33,6 +36,8 @@ module Initials
|
|
33
36
|
end
|
34
37
|
|
35
38
|
def fill
|
39
|
+
return "hsl(0, 0%, 67%)" if @name.empty?
|
40
|
+
|
36
41
|
hue_step = HUE_WHEEL / colors
|
37
42
|
char_sum = name.split("").sum do |c|
|
38
43
|
# Multiplication makes sure neighboring characters (like A and B) are one hue step apart.
|
@@ -41,7 +46,7 @@ module Initials
|
|
41
46
|
|
42
47
|
# Spin the wheel!
|
43
48
|
hue = char_sum % HUE_WHEEL
|
44
|
-
|
49
|
+
|
45
50
|
"hsl(#{hue}, 40%, 40%)"
|
46
51
|
end
|
47
52
|
|
data/lib/initials/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: initials
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Hutterer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|