Class: SimpleAttribute::Attributes::Avatar
- Defined in:
- lib/simple_attribute/attributes/avatar.rb
Instance Attribute Summary
Attributes inherited from Base
#attribute, #options, #record, #value
Instance Method Summary collapse
-
#attribute_name ⇒ Object
Attribute name.
-
#custom_avatar ⇒ Object
Get custom avatar.
-
#gravatar ⇒ Object
Get gravatar.
-
#render_attribute ⇒ Object
Render attribute.
-
#size ⇒ Object
Image size.
Methods inherited from Base
#default_value, #defaults, #html_options, #initialize, #label_method, #method_missing, #render, #render_default_value, #render_with_default, #render_wrapper, #renderer_name, #value?, #wrapper, #wrapper?, #wrapper_html
Constructor Details
This class inherits a constructor from SimpleAttribute::Attributes::Base
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class SimpleAttribute::Attributes::Base
Instance Method Details
#attribute_name ⇒ Object
Attribute name
5 6 7 |
# File 'lib/simple_attribute/attributes/avatar.rb', line 5 def attribute_name 'avatar' end |
#custom_avatar ⇒ Object
Get custom avatar
21 22 23 24 |
# File 'lib/simple_attribute/attributes/avatar.rb', line 21 def custom_avatar attribute = .fetch :avatar, nil record.try attribute if attribute end |
#gravatar ⇒ Object
Get gravatar
15 16 17 18 |
# File 'lib/simple_attribute/attributes/avatar.rb', line 15 def gravatar hash = Digest::MD5::hexdigest(value) "https://www.gravatar.com/avatar/#{hash}?rating=PG&size=#{size}&default=mm" end |
#render_attribute ⇒ Object
Render attribute
27 28 29 30 31 32 33 |
# File 'lib/simple_attribute/attributes/avatar.rb', line 27 def render_attribute avatar = custom_avatar || gravatar classes = "#{[:class]} avatar-image".strip = .merge({ class: classes, width: size, height: size }) image_tag avatar, end |
#size ⇒ Object
Image size
10 11 12 |
# File 'lib/simple_attribute/attributes/avatar.rb', line 10 def size .fetch :size, 19 end |