Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/skittlize.rb
Instance Method Summary collapse
Instance Method Details
#skittle_color ⇒ Object
23 24 25 26 27 28 |
# File 'lib/skittlize.rb', line 23 def skittle_color n = Integer(Digest::MD5.hexdigest("#{self}\n")[-2..-1], 16) n %= 231 n += 17 if [0, 15, 16].include?(n) n end |
#skittlize(options = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/skittlize.rb', line 30 def skittlize( = {}) () if [:split] split([:split]).map(&:skittlize).join([:join] || [:split]) else "\033[38;5;#{skittle_color}m#{self}\033[0m" end end |
#skittlize!(options = {}) ⇒ Object
40 41 42 |
# File 'lib/skittlize.rb', line 40 def skittlize!( = {}) replace(skittlize()) end |