Class: Supertramp::Avatar

Inherits:
Object
  • Object
show all
Defined in:
lib/supertramp/avatar.rb

Constant Summary collapse

SHAPES =
[
  SQUARE = 'square',
  CIRCLE = 'circle',
  ROUNDED = 'rounded'
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(initials:, background:, shape:) ⇒ Avatar

Returns a new instance of Avatar.



14
15
16
17
18
# File 'lib/supertramp/avatar.rb', line 14

def initialize(initials:, background:, shape:)
  @initials = initials
  @background = background
  @shape = shape
end

Instance Method Details

#data_urlObject



20
21
22
# File 'lib/supertramp/avatar.rb', line 20

def data_url
  "data:image/svg+xml;base64,#{Base64.encode64(svg)}"
end

#shapeObject



28
29
30
# File 'lib/supertramp/avatar.rb', line 28

def shape
  bind_template("_#{@shape}")
end

#svgObject



24
25
26
# File 'lib/supertramp/avatar.rb', line 24

def svg
  bind_template('avatar')
end

#text_sizeObject

Scale the text size proportinaly based on the number of initials to ensure they all fit, with a max size of 26



34
35
36
# File 'lib/supertramp/avatar.rb', line 34

def text_size
  [(51.0 / @initials.chars.count).ceil, 26].min
end