Class: LabelColorize::Generator
- Inherits:
-
Object
- Object
- LabelColorize::Generator
- Defined in:
- lib/label_colorize/generator.rb
Instance Attribute Summary collapse
-
#str ⇒ Object
readonly
Returns the value of attribute str.
Instance Method Summary collapse
- #hue ⇒ Object
-
#initialize(str) ⇒ Generator
constructor
A new instance of Generator.
- #rgb ⇒ Object
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
#str ⇒ Object (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
#hue ⇒ Object
17 18 19 |
# File 'lib/label_colorize/generator.rb', line 17 def hue str.hash % 360 end |
#rgb ⇒ Object
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 |