scarf 0.2.1 → 0.2.2

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: d84e27b99920a8976b7b878a7d5206a645a1cb55
4
- data.tar.gz: 1368f9986144687835bf8540b43a132b516bff29
3
+ metadata.gz: 83409d7ba92e1916a731e13f3f3eddefe7ae7c46
4
+ data.tar.gz: b4683a50e8dd5e739e4c435e686cccf50bdf599a
5
5
  SHA512:
6
- metadata.gz: 316a54c777221bfe66258a8edee4a64b1e9e17ad75b96a4ce5ad167872c2b61f97dd642a0df017b4526cd294aa51afdb5d08cf45fef5bb97e553239f1268ca96
7
- data.tar.gz: 9dbf9668a12e450f83ac93a8aa944ba8ee2999ae40fd969bf503ae3cdfe1a089357db776de56402377365be4b7aba134387b08d5677271b3248c8486f75a9390
6
+ metadata.gz: 07d0bfd396807645232bdcbc5c2eb14822678a1acf3c8bce93533dd62ccdd4a9930f6243769fa005f1545dab16ca2722a685e949099a9daf03437f1ddb0ffadf
7
+ data.tar.gz: 5f9247ed99a4922c12fc0db9171776038a3e1b067df936b167da74268d8bb6bb97f966b0804932d43c4f7365162ec903fa2d571be2093b5bf3ffa932ac6e4ec4
data/lib/scarf.rb CHANGED
@@ -1,4 +1,21 @@
1
1
  require 'digest/sha1'
2
+
3
+ require_relative 'scarf/configuration'
2
4
  require_relative 'scarf/image_svg'
3
5
  require_relative 'scarf/identicon'
4
6
  require_relative 'scarf/initial_avatar'
7
+
8
+ # A Ruby library for generating initial avatars and identicons.
9
+ module Scarf
10
+ class << self
11
+ attr_writer :configuration
12
+
13
+ def configuration
14
+ @configuration ||= Configuration.new
15
+ end
16
+
17
+ def configure
18
+ yield(configuration)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,10 @@
1
+ module Scarf
2
+ # Store configuration for this gem.
3
+ class Configuration
4
+ attr_accessor :font_family
5
+
6
+ def initialize
7
+ @font_family = %w(sans-serif)
8
+ end
9
+ end
10
+ end
@@ -2,7 +2,7 @@ module Scarf
2
2
  class InitialAvatar
3
3
  def initialize(name, font_family: [])
4
4
  @name = name
5
- @font_family = font_family
5
+ @font_family = font_family.length > 0 ? font_family : Scarf.configuration.font_family
6
6
  end
7
7
 
8
8
  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
@@ -11,25 +11,22 @@ module Scarf
11
11
  <<~WRAPPER.gsub(/$\s+/, '').strip
12
12
  <svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 100 100">
13
13
  <circle cx="50" cy="50" r="50" fill="#{background_fill}" />
14
- <text fill="#{foreground_fill}" font-size="50" font-family="#{font_family}" x="50" y="50" text-anchor="middle" alignment-baseline="central">#{initials}</text>
14
+ <text fill="#{foreground_fill}" font-size="50" font-family="#{quoted_fonts}" x="50" y="50" text-anchor="middle" alignment-baseline="central">#{initials}</text>
15
15
  </svg>
16
16
  WRAPPER
17
17
  end
18
18
 
19
19
  private
20
20
 
21
- # Default to sans-serif.
22
- def font_family
23
- (quoted_fonts + %w(sans-serif)).join(', ')
24
- end
25
-
26
21
  # Surround the font name with single quotes if there's a space in the name, and isn't quoted already.
27
22
  def quoted_fonts
28
- @font_family.map do |font|
23
+ quoted_fonts = @font_family.map do |font|
29
24
  return font unless font.include?(' ')
30
25
  return font if font[0] == "'"
31
26
  "'#{font}'"
32
27
  end
28
+
29
+ quoted_fonts.join(', ')
33
30
  end
34
31
 
35
32
  # Returns a deterministic background fill for a given name.
data/lib/scarf/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Scarf
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
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.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hari Gopal
@@ -60,6 +60,7 @@ extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
62
  - lib/scarf.rb
63
+ - lib/scarf/configuration.rb
63
64
  - lib/scarf/identicon.rb
64
65
  - lib/scarf/image_svg.rb
65
66
  - lib/scarf/initial_avatar.rb