Class: Gravatar

Inherits:
Object
  • Object
show all
Defined in:
lib/gravatar.rb

Constant Summary collapse

DefaultOptions =

px

{:size => 80}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email = '', options = {}) ⇒ Gravatar

Returns a new instance of Gravatar.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/gravatar.rb', line 8

def initialize(email = '', options = {})
  options = DefaultOptions.merge(options)
  
  @id = Digest::MD5.hexdigest(email)
  
  @url = 'http://gravatar.com/avatar.php?gravatar_id=' + @id
  options.each {|k,v| @url += "&#{k}=#{v}" unless v.nil?}
  
  %w(size rating border default).each do |a|
    instance_variable_set "@#{a}", options[a.to_sym]
  end    
end

Instance Attribute Details

#borderObject

Returns the value of attribute border.



6
7
8
# File 'lib/gravatar.rb', line 6

def border
  @border
end

#defaultObject

Returns the value of attribute default.



6
7
8
# File 'lib/gravatar.rb', line 6

def default
  @default
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/gravatar.rb', line 6

def id
  @id
end

#ratingObject

Returns the value of attribute rating.



6
7
8
# File 'lib/gravatar.rb', line 6

def rating
  @rating
end

#sizeObject

Returns the value of attribute size.



6
7
8
# File 'lib/gravatar.rb', line 6

def size
  @size
end

#urlObject

Returns the value of attribute url.



6
7
8
# File 'lib/gravatar.rb', line 6

def url
  @url
end

Instance Method Details

#to_sObject



21
# File 'lib/gravatar.rb', line 21

def to_s; url; end