supertramp 0.6.1 → 0.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e782e06f94b9db00d129ed79674a626cba15d6dd4aba1f9412ff487600e9e77
4
- data.tar.gz: 46f4119919f82b072578a62009d628e69215745d4d3f33f3bc1c2c624969ae9a
3
+ metadata.gz: fa1142575754c1d43314d313b55baec20d4a5385c2e8b0a30a9835cf970378cf
4
+ data.tar.gz: 6c8e314b5e5849d86fcc3cd51f6619334755852f2eef1a58e0183c2df48c2583
5
5
  SHA512:
6
- metadata.gz: 66b40bd408dbad5300c9659b0fd2cb3e7f38df1d0d3f705bc9f192ebb8c826dec8d648bd66df517897a8787432a44d16d98be6ba93a76e399e0448228854967c
7
- data.tar.gz: 19ef9e61382f857bf1a0e18fddfa970bff2695abd60fbe72d5de6b725b357f971f46600d5e84c50a52dda43a221563558ad65a143edcf0effad29eb0f6879755
6
+ metadata.gz: a6ff049500d0fafcd7a1df059a8febd611636f3bd2e168d6e2398e4f826420de8bab9ee507d53707abc43bfee374effb7b238fb0a94c6c7166ddef7a6a77617a
7
+ data.tar.gz: a7b350d1971bddee8785507a21eec3639ac4b03d920f46a2f8f163652c99026bba848c6230b346cbee13451510e6a0e8d6729dff7b74cc7224e505aaa5969f0c
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'erb'
4
+ require 'base64'
4
5
 
5
6
  class Supertramp
6
7
  class Avatar
@@ -16,7 +17,11 @@ class Supertramp
16
17
  @shape = shape
17
18
  end
18
19
 
19
- def to_s
20
+ def data_url
21
+ "data:image/svg+xml;base64,#{Base64.encode64(svg)}"
22
+ end
23
+
24
+ def svg
20
25
  bind_template('avatar')
21
26
  end
22
27
 
@@ -24,6 +29,12 @@ class Supertramp
24
29
  bind_template("_#{@shape}")
25
30
  end
26
31
 
32
+ # Scale the text size proportinaly based on the number of initials
33
+ # to ensure they all fit, with a max size of 26
34
+ def text_size
35
+ [(51.0 / @initials.chars.count).ceil, 26].min
36
+ end
37
+
27
38
  private
28
39
 
29
40
  def bind_template(file)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Supertramp
4
- VERSION = '0.6.1'
4
+ VERSION = '0.8.1'
5
5
  end
data/lib/supertramp.rb CHANGED
@@ -16,7 +16,19 @@ class Supertramp
16
16
  end
17
17
 
18
18
  def to_s
19
- Avatar.new(initials: initials, background: background, shape: shape).to_s
19
+ avatar.svg
20
+ end
21
+
22
+ def data_url
23
+ avatar.data_url
24
+ end
25
+
26
+ def self.svg(**options)
27
+ new(**options).to_s
28
+ end
29
+
30
+ def self.data_url(**options)
31
+ new(**options).data_url
20
32
  end
21
33
 
22
34
  def self.configure
@@ -27,6 +39,10 @@ class Supertramp
27
39
 
28
40
  attr_accessor :name
29
41
 
42
+ def avatar
43
+ @avatar ||= Avatar.new(initials: initials, background: background, shape: shape)
44
+ end
45
+
30
46
  def validate_arguments
31
47
  raise ArgumentError, 'either `initials:` or `name:` must be specified' unless @name || @initials
32
48
  raise ArgumentError, "`shape:` must be one of #{Avatar::SHAPES}" unless Avatar::SHAPES.include?(shape)
@@ -1,7 +1,7 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 50 50">
3
3
  <%= shape %>
4
- <text fill="#fff" font-family="Helvetica,Arial,sans-serif" font-size="26" font-weight="500" x="50%" y="55%" dominant-baseline="middle" text-anchor="middle">
4
+ <text fill="#fff" font-family="Helvetica,Arial,sans-serif" font-size="<%= text_size %>" font-weight="500" x="50%" y="55%" dominant-baseline="middle" text-anchor="middle">
5
5
  <%= @initials %>
6
6
  </text>
7
7
  </svg>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: supertramp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Bearman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-31 00:00:00.000000000 Z
11
+ date: 2022-06-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: