Class: String

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

Instance Method Summary collapse

Instance Method Details

#skittle_colorObject



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(options = {})
  check_options(options)

  if options[:split]
    split(options[:split]).map(&:skittlize).join(options[:join] || options[: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!(options = {})
  replace(skittlize(options))
end