Class: LabelColorize::Generator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ Generator

Returns a new instance of Generator.



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

def initialize(str)
  @str = str
end

Instance Attribute Details

#strObject (readonly)

Returns the value of attribute str.



3
4
5
# File 'lib/label_colorize/generator.rb', line 3

def str
  @str
end

Instance Method Details

#hueObject



17
18
19
# File 'lib/label_colorize/generator.rb', line 17

def hue
  str.hash % 360
end

#rgbObject



9
10
11
12
13
14
15
# File 'lib/label_colorize/generator.rb', line 9

def rgb
  return nil unless str

  # Credits to Dominik Scholer
  # https://makandracards.com/makandra/24449-hash-any-ruby-object-into-an-rgb-color
  '%06x' % (str.hash & 0xffffff)
end