Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/slacktail/extensions/string.rb

Instance Method Summary collapse

Instance Method Details

#hex_color?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/slacktail/extensions/string.rb', line 18

def hex_color?
  match /^[0-9a-fA-F]{6}$/
end

#round_colorObject



22
23
24
25
26
# File 'lib/slacktail/extensions/string.rb', line 22

def round_color
  return self unless hex_color?
  rgb = scan(/.{2}/).map { |h| ((h.to_i(16) / 255.0).round * 15).to_s(16) }
  rgb.map { |c| "#{c}#{c}" }.join
end

#to_colsole_colorObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/slacktail/extensions/string.rb', line 2

def to_colsole_color
  color = {
    '000000' => :k,
    'ff0000' => :r,
    '00ff00' => :g,
    '0000ff' => :b,
    'ffff00' => :y,
    'ff00ff' => :m,
    '00ffff' => :c,
    'ffffff' => :w,
  }

  key = self.downcase.round_color
  color.keys.include?(key) ? color[key] : :n
end