class Supertramp::Avatar
Constants
- SHAPES
Public Class Methods
new(initials:, background:, shape:)
click to toggle source
# File lib/supertramp/avatar.rb, line 13 def initialize(initials:, background:, shape:) @initials = initials @background = background @shape = shape end
Public Instance Methods
shape()
click to toggle source
# File lib/supertramp/avatar.rb, line 23 def shape bind_template("_#{@shape}") end
text_size()
click to toggle source
Scale the text size proportinaly based on the number of initials to ensure they all fit, with a max size of 26
# File lib/supertramp/avatar.rb, line 29 def text_size [(51.0 / @initials.chars.count).ceil, 26].min end
to_s()
click to toggle source
# File lib/supertramp/avatar.rb, line 19 def to_s bind_template('avatar') end
Private Instance Methods
bind_template(file)
click to toggle source
# File lib/supertramp/avatar.rb, line 35 def bind_template(file) ERB.new(template(file)).result(binding) end
template(file)
click to toggle source
# File lib/supertramp/avatar.rb, line 39 def template(file) File.read(template_path(file)) end
template_path(file)
click to toggle source
# File lib/supertramp/avatar.rb, line 43 def template_path(file) File.expand_path("../templates/#{file}.svg.erb", File.dirname(__FILE__)) end