Class: LetterAvatar::Identity

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#colorObject

Returns the value of attribute color.



5
6
7
# File 'lib/letter_avatar.rb', line 5

def color
  @color
end

#letterObject

Returns the value of attribute letter.



5
6
7
# File 'lib/letter_avatar.rb', line 5

def letter
  @letter
end

Class Method Details

.from_username(username) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/letter_avatar.rb', line 7

def self.from_username(username)
  identity = new
  identity.color =
    LetterAvatar::COLORS[
      Digest::MD5.hexdigest(username)[0...15].to_i(16) % LetterAvatar::COLORS.length
    ]
  identity.letter = username[0].upcase
  identity
end