Class: T::Identicon

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number) ⇒ Identicon

Returns a new instance of Identicon.



9
10
11
12
13
14
15
16
17
18
# File 'lib/t/identicon.rb', line 9

def initialize(number)
  # Bottom six bits
  @bits = number & 0x3f

  # Next highest eight bits
  @fcolor = (number >> 6) & 0xff

  # Next highest eight bits
  @bcolor = (number >> 14) & 0xff
end

Instance Attribute Details

#bitsObject

Six-bit number (0-63)



4
5
6
# File 'lib/t/identicon.rb', line 4

def bits
  @bits
end

#colorObject

Eight-bit number (0-255)



7
8
9
# File 'lib/t/identicon.rb', line 7

def color
  @color
end

Class Method Details

.for_user_name(string) ⇒ Object



38
39
40
# File 'lib/t/identicon.rb', line 38

def for_user_name(string)
  Identicon.new(digest(string))
end

Instance Method Details

#linesObject



20
21
22
23
24
# File 'lib/t/identicon.rb', line 20

def lines
  ["#{bg @bits[0]}  #{bg @bits[1]}  #{bg @bits[0]}  #{reset}",
   "#{bg @bits[2]}  #{bg @bits[3]}  #{bg @bits[2]}  #{reset}",
   "#{bg @bits[4]}  #{bg @bits[5]}  #{bg @bits[4]}  #{reset}"]
end