Class: Animal::Identicon

Inherits:
Object
  • Object
show all
Defined in:
lib/animal/identicon.rb,
lib/animal/identicon/version.rb

Defined Under Namespace

Classes: TypeError

Constant Summary collapse

VERSION =
"0.1.0"

Instance Method Summary collapse

Constructor Details

#initialize(identifier) ⇒ Identicon

Returns a new instance of Identicon.



8
9
10
# File 'lib/animal/identicon.rb', line 8

def initialize(identifier)
  @identifier = identifier
end

Instance Method Details

#to_svg(size = 128, type: "square") ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/animal/identicon.rb', line 12

def to_svg(size = 128, type: "square")
  digits = generate_digits
  icon   = generate_icon(digits)
  color  = generate_color(digits)

  case type
  when "circle"
    radius = 50
  when "square"
    radius = 0
  else
    raise TypeError.new("Please pass type 'circle' or 'square'")
  end

  "<svg style='background-color: ##{color}; height: #{size}px; width: #{size}px; border-radius: #{radius}%;'>
    <image xlink:href='https://ssl.gstatic.com/docs/common/profile/#{icon}_lg.png' style='height: #{size}px; width: #{size}px'></image>
   </svg>"
end