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.
8 9 10 11 |
# File 'lib/initial_avatar/avatar.rb', line 8 def initialize(text, = {}) @text = text.upcase @opts = InitialAvatar.configuration..merge() end |
Instance Attribute Details
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
6 7 8 |
# File 'lib/initial_avatar/avatar.rb', line 6 def opts @opts end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
5 6 7 |
# File 'lib/initial_avatar/avatar.rb', line 5 def text @text end |
Instance Method Details
#data_uri ⇒ Object
21 22 23 |
# File 'lib/initial_avatar/avatar.rb', line 21 def data_uri "data:image/svg+xml;base64,#{Base64.strict_encode64(svg_tag)}" end |
#svg_tag ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/initial_avatar/avatar.rb', line 13 def svg_tag " <svg xmlns=\"http://www.w3.org/2000/svg\" pointer-events=\"none\" width=\"\#{opts[:size]}\" height=\"\#{opts[:size]}\" style=\"background-color: \#{color};\">\n <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>\n </svg>\n SVG\nend\n" |