Class: BoringAvatar::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/boring_avatar/avatar/base.rb

Direct Known Subclasses

Bauhaus, Beam, Marble, Ring, Sunset

Constant Summary collapse

COLORS =
%w[#92a1c6 #146a7c #f0ab3d #c271b4 #c20d90].freeze
NAME =
"Clara Barton".freeze
SIZE =
40.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(colors: COLORS, name: NAME, size: SIZE, **opts) ⇒ Base

Returns a new instance of Base.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/boring_avatar/avatar/base.rb', line 11

def initialize(colors: COLORS, name: NAME, size: SIZE, **opts)
  @colors = case
  when colors == "random"
    Util.random_palette
  when colors.nil? || colors.empty?
    COLORS
  else
    colors
  end
  @name = name
  @size = size.nil? ? SIZE : size
  @opts = opts
  @num_from_name = Util.get_number(name)
  @range = @colors.length
end

Instance Attribute Details

#colors ⇒ Object (readonly)

Returns the value of attribute colors.



9
10
11
# File 'lib/boring_avatar/avatar/base.rb', line 9

def colors
  @colors
end

#name ⇒ Object (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/boring_avatar/avatar/base.rb', line 9

def name
  @name
end

#num_from_name ⇒ Object (readonly)

Returns the value of attribute num_from_name.



9
10
11
# File 'lib/boring_avatar/avatar/base.rb', line 9

def num_from_name
  @num_from_name
end

#opts ⇒ Object (readonly)

Returns the value of attribute opts.



9
10
11
# File 'lib/boring_avatar/avatar/base.rb', line 9

def opts
  @opts
end

#range ⇒ Object (readonly)

Returns the value of attribute range.



9
10
11
# File 'lib/boring_avatar/avatar/base.rb', line 9

def range
  @range
end

#size ⇒ Object (readonly)

Returns the value of attribute size.



9
10
11
# File 'lib/boring_avatar/avatar/base.rb', line 9

def size
  @size
end

Instance Method Details

#generate ⇒ Object



27
28
29
# File 'lib/boring_avatar/avatar/base.rb', line 27

def generate
  render_svg(template)
end