Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/slacktail/extensions/string.rb
Instance Method Summary collapse
Instance Method Details
#hex_color? ⇒ Boolean
18 19 20 |
# File 'lib/slacktail/extensions/string.rb', line 18 def hex_color? match /^[0-9a-fA-F]{6}$/ end |
#round_color ⇒ Object
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_color ⇒ Object
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' => :blk, 'ff0000' => :red, '00ff00' => :grn, '0000ff' => :blu, 'ffff00' => :ylw, 'ff00ff' => :pur, '00ffff' => :cyn, 'ffffff' => :wht, } key = self.downcase.round_color color.keys.include?(key) ? color[key] : :rst end |