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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a32418ae1867d5b433b912e3d2caf903fb856cc7
4
- data.tar.gz: 306f599cddd5e45ae196602e83484531d0c28aa7
3
+ metadata.gz: 0fec22c3e782afe9866babe54d7f61a5e158fd41
4
+ data.tar.gz: 9d50a573df25036b9b05ba357f0bb6d42d12b982
5
5
  SHA512:
6
- metadata.gz: 903608e5c91661a502524467265a4914323efa87210ccdb5660722b20fbcec50a942869b1636e3891f96531494a5cda31ca9c9348fde42b5678b95f8eba4f2ea
7
- data.tar.gz: 5a28bb71a8b3902e4c08a28cb3c720e34034559cea2106f6d231b0f39a3f1e09440139e3d12f4ba96a2681806dd5dd032b9147c5201f7bddbdb6482b72bac2a0
6
+ metadata.gz: '09a4f2f5195e0d965d5625c3723311a9d778fa12c31556694e3c3dd2bde2695cec8d10aa52b3f72e500f817f8df16ebe59f9ac247ff8116838d4a0d7792440f3'
7
+ data.tar.gz: c33a288fd0f4042b04a5b2e62ae67854c31a7a8bb11b7819b7df6aedbb7339e23a8119ec175a1d90c7845d573e395914f73f9a8e6a848c3d88a9213a281881ff
@@ -2,9 +2,11 @@ module Scarf
2
2
  # Store configuration for this gem.
3
3
  class Configuration
4
4
  attr_accessor :font_family
5
+ attr_accessor :background_shape
5
6
 
6
7
  def initialize
7
8
  @font_family = %w(sans-serif)
9
+ @background_shape = :circle
8
10
  end
9
11
  end
10
12
  end
@@ -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 > 0 ? font_family : Scarf.configuration.font_family
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
- <circle cx="50" cy="50" r="50" fill="#{background_fill}" />
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
@@ -1,3 +1,3 @@
1
1
  module Scarf
2
- VERSION = '0.2.3'
2
+ VERSION = '0.2.4'
3
3
  end
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.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hari Gopal