class Supertramp
Constants
- VERSION
Attributes
name[RW]
Public Class Methods
configure() { |config| ... }
click to toggle source
# File lib/supertramp.rb, line 22 def self.configure yield @@config end
new(initials: nil, name: nil, background: nil, shape: nil)
click to toggle source
# File lib/supertramp.rb, line 9 def initialize(initials: nil, name: nil, background: nil, shape: nil) @initials = initials @name = name @background = background @shape = shape validate_arguments end
Public Instance Methods
to_s()
click to toggle source
# File lib/supertramp.rb, line 18 def to_s Avatar.new(initials: initials, background: background, shape: shape).to_s end
Private Instance Methods
background()
click to toggle source
# File lib/supertramp.rb, line 51 def background @background ||= background_for_initials end
background_for_initials()
click to toggle source
# File lib/supertramp.rb, line 55 def background_for_initials Random.srand(initials_seed) index = (rand * config.colours.length).floor config.colours[index] end
config()
click to toggle source
# File lib/supertramp.rb, line 35 def config @@config end
initials()
click to toggle source
# File lib/supertramp.rb, line 39 def initials @initials ||= initials_from_name return @initials.upcase if config.uppercase @initials end
initials_from_name()
click to toggle source
# File lib/supertramp.rb, line 47 def initials_from_name name.split.map { |n| n[0] }.join end
initials_seed()
click to toggle source
# File lib/supertramp.rb, line 61 def initials_seed initials.downcase.chars.map(&:ord).sum end
shape()
click to toggle source
# File lib/supertramp.rb, line 65 def shape @shape ||= config.shape end
validate_arguments()
click to toggle source
# File lib/supertramp.rb, line 30 def validate_arguments raise ArgumentError, 'either `initials:` or `name:` must be specified' unless @name || @initials raise ArgumentError, "`shape:` must be one of #{Avatar::SHAPES}" unless Avatar::SHAPES.include?(shape) end