Class: Color

Inherits:
Object show all
Defined in:
lib/vv/style/color.rb

Overview

Some code retrieved from rainbow gem, license followed: github.com/sickill/rainbow At commit: 0425bb46a408e406501c842d97233f13d93701e3

Constant Summary collapse

NAMES =
{
  aqua: [0, 255, 255],
  aquamarine: [127, 255, 212],
  mediumaquamarine: [102, 205, 170],
  azure: [240, 255, 255],
  beige: [245, 245, 220],
  bisque: [255, 228, 196],
  black: [0, 0, 0],
  blanchedalmond: [255, 235, 205],
  blue: [0, 0, 255],
  darkblue: [0, 0, 139],
  lightblue: [173, 216, 230],
  mediumblue: [0, 0, 205],
  aliceblue: [240, 248, 255],
  cadetblue: [95, 158, 160],
  dodgerblue: [30, 144, 255],
  midnightblue: [25, 25, 112],
  navyblue: [0, 0, 128],
  powderblue: [176, 224, 230],
  royalblue: [65, 105, 225],
  skyblue: [135, 206, 235],
  deepskyblue: [0, 191, 255],
  lightskyblue: [135, 206, 250],
  slateblue: [106, 90, 205],
  darkslateblue: [72, 61, 139],
  mediumslateblue: [123, 104, 238],
  steelblue: [70, 130, 180],
  lightsteelblue: [176, 196, 222],
  brown: [165, 42, 42],
  rosybrown: [188, 143, 143],
  saddlebrown: [139, 69, 19],
  sandybrown: [244, 164, 96],
  burlywood: [222, 184, 135],
  chartreuse: [127, 255, 0],
  chocolate: [210, 105, 30],
  coral: [255, 127, 80],
  lightcoral: [240, 128, 128],
  cornflower: [100, 149, 237],
  cornsilk: [255, 248, 220],
  crimson: [220, 20, 60],
  cyan: [0, 255, 255],
  darkcyan: [0, 139, 139],
  lightcyan: [224, 255, 255],
  firebrick: [178, 34, 34],
  fuchsia: [255, 0, 255],
  gainsboro: [220, 220, 220],
  gold: [255, 215, 0],
  goldenrod: [218, 165, 32],
  darkgoldenrod: [184, 134, 11],
  lightgoldenrod: [250, 250, 210],
  palegoldenrod: [238, 232, 170],
  gray: [190, 190, 190],
  darkgray: [169, 169, 169],
  dimgray: [105, 105, 105],
  lightgray: [211, 211, 211],
  slategray: [112, 128, 144],
  lightslategray: [119, 136, 153],
  webgray: [128, 128, 128],
  green: [0, 255, 0],
  darkgreen: [0, 100, 0],
  lightgreen: [144, 238, 144],
  palegreen: [152, 251, 152],
  darkolivegreen: [85, 107, 47],
  yellowgreen: [154, 205, 50],
  forestgreen: [34, 139, 34],
  lawngreen: [124, 252, 0],
  limegreen: [50, 205, 50],
  seagreen: [46, 139, 87],
  darkseagreen: [143, 188, 143],
  lightseagreen: [32, 178, 170],
  mediumseagreen: [60, 179, 113],
  springgreen: [0, 255, 127],
  mediumspringgreen: [0, 250, 154],
  webgreen: [0, 128, 0],
  honeydew: [240, 255, 240],
  indianred: [205, 92, 92],
  indigo: [75, 0, 130],
  ivory: [255, 255, 240],
  khaki: [240, 230, 140],
  darkkhaki: [189, 183, 107],
  lavender: [230, 230, 250],
  lavenderblush: [255, 240, 245],
  lemonchiffon: [255, 250, 205],
  lime: [0, 255, 0],
  linen: [250, 240, 230],
  magenta: [255, 0, 255],
  darkmagenta: [139, 0, 139],
  maroon: [176, 48, 96],
  webmaroon: [127, 0, 0],
  mintcream: [245, 255, 250],
  mistyrose: [255, 228, 225],
  moccasin: [255, 228, 181],
  oldlace: [253, 245, 230],
  olive: [128, 128, 0],
  olivedrab: [107, 142, 35],
  orange: [255, 165, 0],
  darkorange: [255, 140, 0],
  orchid: [218, 112, 214],
  darkorchid: [153, 50, 204],
  mediumorchid: [186, 85, 211],
  papayawhip: [255, 239, 213],
  peachpuff: [255, 218, 185],
  peru: [205, 133, 63],
  pink: [255, 192, 203],
  deeppink: [255, 20, 147],
  lightpink: [255, 182, 193],
  hotpink: [255, 105, 180],
  plum: [221, 160, 221],
  purple: [160, 32, 240],
  mediumpurple: [147, 112, 219],
  rebeccapurple: [102, 51, 153],
  webpurple: [127, 0, 127],
  red: [255, 0, 0],
  darkred: [139, 0, 0],
  orangered: [255, 69, 0],
  mediumvioletred: [199, 21, 133],
  palevioletred: [219, 112, 147],
  salmon: [250, 128, 114],
  darksalmon: [233, 150, 122],
  lightsalmon: [255, 160, 122],
  seashell: [255, 245, 238],
  sienna: [160, 82, 45],
  silver: [192, 192, 192],
  darkslategray: [47, 79, 79],
  snow: [255, 250, 250],
  tan: [210, 180, 140],
  teal: [0, 128, 128],
  thistle: [216, 191, 216],
  tomato: [255, 99, 71],
  turquoise: [64, 224, 208],
  darkturquoise: [0, 206, 209],
  mediumturquoise: [72, 209, 204],
  paleturquoise: [175, 238, 238],
  violet: [238, 130, 238],
  darkviolet: [148, 0, 211],
  blueviolet: [138, 43, 226],
  wheat: [245, 222, 179],
  white: [255, 255, 255],
  antiquewhite: [250, 235, 215],
  floralwhite: [255, 250, 240],
  ghostwhite: [248, 248, 255],
  navajowhite: [255, 222, 173],
  whitesmoke: [245, 245, 245],
  yellow: [255, 255, 0],
  lightyellow: [255, 255, 224],
  greenyellow: [173, 255, 47]
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, hex: nil, rgb: nil) ⇒ Color

Returns a new instance of Color.

Raises:

  • (NotImplemented)


177
178
179
180
181
182
183
184
185
186
187
# File 'lib/vv/style/color.rb', line 177

def initialize name=nil, hex: nil, rgb: nil
  raise NotImplemented if name.nil?
  raise NotImplemented if hex.present?
  raise NotImplemented if rgb.present?

  color ||= self.class.lookup_color name

  raise NotImplemented unless color.present?

  @r, @g, @b = color
end

Instance Attribute Details

#bObject

Returns the value of attribute b.



153
154
155
# File 'lib/vv/style/color.rb', line 153

def b
  @b
end

#gObject

Returns the value of attribute g.



153
154
155
# File 'lib/vv/style/color.rb', line 153

def g
  @g
end

#rObject

Returns the value of attribute r.



153
154
155
# File 'lib/vv/style/color.rb', line 153

def r
  @r
end

Class Method Details

.known_color?(name) ⇒ Boolean

Returns:

  • (Boolean)


173
174
175
# File 'lib/vv/style/color.rb', line 173

def self.known_color? name
  self.lookup_color(name).present?
end

.lookup_color(name) ⇒ Object



164
165
166
167
168
169
170
171
# File 'lib/vv/style/color.rb', line 164

def self.lookup_color name
  name = name.to_s
  name.gsub! "_", ""
  name.gsub! "-", ""
  name = name.to_sym

  NAMES[name]
end

.namesObject



155
156
157
158
159
160
161
162
# File 'lib/vv/style/color.rb', line 155

def self.names
  NAMES.each do | name, _ |
    styled_name = name.to_s.style name
    styled_name += " (black)" if name == :black
    puts styled_name
  end
  nil
end

Instance Method Details

#blueObject



197
198
199
# File 'lib/vv/style/color.rb', line 197

def blue
  @b
end

#codeObject



205
206
207
# File 'lib/vv/style/color.rb', line 205

def code
  "#{start_code}#{@r};#{@g};#{@b}m"
end

#greenObject



193
194
195
# File 'lib/vv/style/color.rb', line 193

def green
  @g
end

#htmlObject Also known as: hex



209
210
211
# File 'lib/vv/style/color.rb', line 209

def html
  "##{@r.to_s(16)}#{@g.to_s(16)}#{@b.to_s(16)}"
end

#redObject



189
190
191
# File 'lib/vv/style/color.rb', line 189

def red
  @r
end

#rgbObject



201
202
203
# File 'lib/vv/style/color.rb', line 201

def rgb
  [@r, @g, @b]
end

#start_codeObject



214
215
216
# File 'lib/vv/style/color.rb', line 214

def start_code
  "\x1b[38;2;"
end