Class: SimpleAttribute::Attributes::Avatar
- Inherits:
-
Base
- Object
- Base
- SimpleAttribute::Attributes::Avatar
show all
- Defined in:
- lib/simple_attribute/attributes/avatar.rb
Instance Attribute Summary
Attributes inherited from Base
#attribute, #options, #record, #value
Instance Method Summary
collapse
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
Instance Method Details
#attribute_name ⇒ Object
4
5
6
|
# File 'lib/simple_attribute/attributes/avatar.rb', line 4
def attribute_name
'avatar'
end
|
#custom_avatar ⇒ Object
17
18
19
20
|
# File 'lib/simple_attribute/attributes/avatar.rb', line 17
def custom_avatar
attribute = options.fetch :avatar, nil
record.try attribute if attribute
end
|
#gravatar ⇒ Object
12
13
14
15
|
# File 'lib/simple_attribute/attributes/avatar.rb', line 12
def gravatar
hash = Digest::MD5::hexdigest(value)
"https://www.gravatar.com/avatar/#{hash}?rating=PG&size=#{size}&default=mm"
end
|
#render_attribute ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/simple_attribute/attributes/avatar.rb', line 22
def render_attribute
avatar = custom_avatar || gravatar
classes = "#{html_options[:class]} avatar-image".strip
options = html_options.merge({ class: classes, width: size, height: size })
image_tag avatar, options
end
|
#size ⇒ Object
8
9
10
|
# File 'lib/simple_attribute/attributes/avatar.rb', line 8
def size
options.fetch :size, 19
end
|