Class: Unmagic::Color::Console::Card

Inherits:
Object
  • Object
show all
Defined in:
lib/unmagic/color/console/card.rb

Overview

Renders a comprehensive “profile card” for a color.

Displays the color’s values in all color spaces (RGB, HSL, OKLCH), harmony colors, and variations (shades, tints, tones).

Examples:

Basic usage

card = Unmagic::Color::Console::Card.new("#FF5733")
puts card.render

With a color object

color = Unmagic::Color.parse("rebeccapurple")
puts Unmagic::Color::Console::Card.new(color)

Constant Summary collapse

WIDTH =

Width of the card in characters (excluding box borders)

72

Instance Method Summary collapse

Constructor Details

#initialize(color) ⇒ Card

Returns a new instance of Card.



25
26
27
28
# File 'lib/unmagic/color/console/card.rb', line 25

def initialize(color)
  @color = Color.parse(color)
  @highlighter = Highlighter.new
end

Instance Method Details

#renderString

Render the color profile card as a string.

Returns:

  • (String)

    The formatted card with ANSI color codes



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/unmagic/color/console/card.rb', line 33

def render
  lines = []
  lines << top_border
  lines.concat(header_rows)
  lines << separator
  lines.concat(harmony_rows)
  lines << separator
  lines.concat(variation_rows)
  lines << bottom_border
  lines.join("\n")
end

#to_sString

Returns The rendered card.

Returns:

  • (String)

    The rendered card



46
47
48
# File 'lib/unmagic/color/console/card.rb', line 46

def to_s
  render
end