Class: Supertramp::Avatar
- Inherits:
-
Object
- Object
- Supertramp::Avatar
- Defined in:
- lib/supertramp/avatar.rb
Constant Summary collapse
- SHAPES =
[ SQUARE = 'square', CIRCLE = 'circle', ROUNDED = 'rounded' ].freeze
Instance Method Summary collapse
- #data_url ⇒ Object
-
#initialize(initials:, background:, shape:) ⇒ Avatar
constructor
A new instance of Avatar.
- #shape ⇒ Object
- #svg ⇒ Object
-
#text_size ⇒ Object
Scale the text size proportinaly based on the number of initials to ensure they all fit, with a max size of 26.
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_url ⇒ Object
20 21 22 |
# File 'lib/supertramp/avatar.rb', line 20 def data_url "data:image/svg+xml;base64,#{Base64.encode64(svg)}" end |
#shape ⇒ Object
28 29 30 |
# File 'lib/supertramp/avatar.rb', line 28 def shape bind_template("_#{@shape}") end |
#svg ⇒ Object
24 25 26 |
# File 'lib/supertramp/avatar.rb', line 24 def svg bind_template('avatar') end |
#text_size ⇒ Object
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 |