Class: PaintbrushSupport::HexColorCode

Inherits:
Object
  • Object
show all
Defined in:
lib/paintbrush_support/hex_color_code.rb

Overview

Translates a string in format ‘hex_ff00ff` or `hex_f0f` into an RGB escape code sequence. Allows calling e.g.:

paintbrush { hex_ff0ff ‘hello in magenta’ }

Instance Method Summary collapse

Constructor Details

#initialize(hex_code:) ⇒ HexColorCode

Returns a new instance of HexColorCode.



10
11
12
# File 'lib/paintbrush_support/hex_color_code.rb', line 10

def initialize(hex_code:)
  @hex_code = hex_code
end

Instance Method Details

#escape_sequenceObject



14
15
16
# File 'lib/paintbrush_support/hex_color_code.rb', line 14

def escape_sequence
  (%w[38 2] + encoded_pairs).join(';')
end