Class: Col::DB
- Inherits:
-
Object
- Object
- Col::DB
- Defined in:
- lib/col.rb
Overview
————————————————————————— #
Constant Summary collapse
- COLORS =
{ 'B' => :black, 'r' => :red, 'g' => :green, 'y' => :yellow, 'b' => :blue, 'm' => :magenta, 'c' => :cyan, 'w' => :white }
- STYLES =
{ 'b' => :bold, 'd' => :dark, 'i' => :italic, 'u' => :underline, 'U' => :underscore, 'k' => :blink, 'r' => :rapid_blink, 'n' => :negative, 'c' => :concealed, 's' => :strikethrough, }
- BACKGROUND =
{ 'oB' => :on_black, 'or' => :on_red, 'og' => :on_green, 'oy' => :on_yellow, 'ob' => :on_blue, 'om' => :on_magenta, 'oc' => :on_cyan, 'ow' => :on_white }
- ALL_METHODS_SYMBOL =
COLORS.values + STYLES.values + BACKGROUND.values
- ALL_METHODS_STRING =
ALL_METHODS_SYMBOL.map { |x| x.to_s }
- ALL_METHODS =
Class Method Summary collapse
- .background(key) ⇒ Object
- .color(key) ⇒ Object
-
.get_value(hash, key, name) ⇒ Object
If the ‘key’ is nil, we return nil.
- .method?(x) ⇒ Boolean
- .style(key) ⇒ Object
Class Method Details
.background(key) ⇒ Object
327 328 329 |
# File 'lib/col.rb', line 327 def self.background(key) get_value BACKGROUND, key, "background color" end |
.color(key) ⇒ Object
319 320 321 |
# File 'lib/col.rb', line 319 def self.color(key) get_value COLORS, key, "color" end |
.get_value(hash, key, name) ⇒ Object
If the ‘key’ is nil, we return nil. Otherwise, we insist that the key be a valid color, style or background color. If it’s not, we raise an error (that’s what ‘name’ is for).
Return the method name sought: :green, :bold, :on_white, etc.
336 337 338 339 340 341 342 343 344 345 346 |
# File 'lib/col.rb', line 336 def self.get_value(hash, key, name) if key.nil? nil else method = hash[key.to_s] if method.nil? raise Col::Error, "Invalid #{name} code: #{key}" end method end end |
.method?(x) ⇒ Boolean
315 316 317 |
# File 'lib/col.rb', line 315 def self.method?(x) ALL_METHODS.include? x end |
.style(key) ⇒ Object
323 324 325 |
# File 'lib/col.rb', line 323 def self.style(key) get_value STYLES, key, "style" end |