Class: EasyGravatar::Gravatar

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

Direct Known Subclasses

Gravatar

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email) ⇒ Gravatar

Returns a new instance of Gravatar.



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

def initialize(email)
  if email && email.length > 0
    @valid_email = true
  else
    email = ''
  end

 @md5 = Digest::MD5.hexdigest(email.downcase)
end

Instance Attribute Details

#md5Object (readonly)

Returns the value of attribute md5.



8
9
10
# File 'lib/easy_gravatar/gravatar.rb', line 8

def md5
  @md5
end

Instance Method Details

#avatar(width = 80) ⇒ Object



29
30
31
# File 'lib/easy_gravatar/gravatar.rb', line 29

def avatar(width = 80)
  "#{get_value(:thumbnailUrl)}?w=#{width}"
end

#full_nameObject



25
26
27
# File 'lib/easy_gravatar/gravatar.rb', line 25

def full_name
  get_value :formattedName
end

#get_value(key, subkey = nil) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/easy_gravatar/gravatar.rb', line 33

def get_value(key, subkey = nil)
  return '' unless @valid_email
  return '' unless hash[key]
  return '' if subkey and !hash[key][subkey]

  return hash[key][subkey] if subkey

  hash[key]
end

#hashObject



20
21
22
23
# File 'lib/easy_gravatar/gravatar.rb', line 20

def hash
  return {} unless @valid_email
  @hash ||= EasyGravatar::JsonParser.for(get_hash).parse
end