Class: InitialAvatar::Avatar
- Inherits:
-
Object
- Object
- InitialAvatar::Avatar
- Defined in:
- lib/initial_avatar/avatar.rb
Instance Attribute Summary collapse
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
- #data_uri ⇒ Object
-
#initialize(text, options = {}) ⇒ Avatar
constructor
A new instance of Avatar.
- #svg_tag ⇒ Object
Constructor Details
#initialize(text, options = {}) ⇒ Avatar
Returns a new instance of Avatar.
6 7 8 9 |
# File 'lib/initial_avatar/avatar.rb', line 6 def initialize(text, = {}) @text = text.upcase @opts = InitialAvatar.configuration..merge() end |
Instance Attribute Details
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
4 5 6 |
# File 'lib/initial_avatar/avatar.rb', line 4 def opts @opts end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
3 4 5 |
# File 'lib/initial_avatar/avatar.rb', line 3 def text @text end |
Instance Method Details
#data_uri ⇒ Object
19 20 21 |
# File 'lib/initial_avatar/avatar.rb', line 19 def data_uri "data:image/svg+xml;base64,#{Base64.strict_encode64(svg_tag)}" end |
#svg_tag ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/initial_avatar/avatar.rb', line 11 def svg_tag <<~SVG <svg xmlns="http://www.w3.org/2000/svg" pointer-events="none" width="#{opts[:size]}" height="#{opts[:size]}" style="background-color: #{color};"> <text text-anchor="middle" y="50%" x="50%" dy="0.35em" pointer-events="auto" fill="#{opts[:text_color]}" font-family="#{opts[:font_family]}" style="font-weight: #{opts[:font_weight]}; font-size: #{font_size}px;">#{text}</text> </svg> SVG end |