Class: PaintbrushSupport::ColorElement

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

Overview

Provides a substring enclosed in unique escape codes for later colorization when the full string has been created and all interpolation is completed. Adds itself to a provided stack of ColorElement objects on initialization.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stack:, code:, string:) ⇒ ColorElement

Returns a new instance of ColorElement.



11
12
13
14
15
16
17
# File 'lib/paintbrush_support/color_element.rb', line 11

def initialize(stack:, code:, string:)
  @stack = stack
  @code = code
  @string = string
  @index = stack.size
  stack << self
end

Instance Attribute Details

#close_indexObject

Returns the value of attribute close_index.



9
10
11
# File 'lib/paintbrush_support/color_element.rb', line 9

def close_index
  @close_index
end

#codeObject (readonly)

Returns the value of attribute code.



8
9
10
# File 'lib/paintbrush_support/color_element.rb', line 8

def code
  @code
end

#indexObject (readonly)

Returns the value of attribute index.



8
9
10
# File 'lib/paintbrush_support/color_element.rb', line 8

def index
  @index
end

#open_indexObject

Returns the value of attribute open_index.



9
10
11
# File 'lib/paintbrush_support/color_element.rb', line 9

def open_index
  @open_index
end

#stackObject (readonly)

Returns the value of attribute stack.



8
9
10
# File 'lib/paintbrush_support/color_element.rb', line 8

def stack
  @stack
end

#stringObject (readonly)

Returns the value of attribute string.



8
9
10
# File 'lib/paintbrush_support/color_element.rb', line 8

def string
  @string
end

Instance Method Details

#inspectObject



23
24
25
# File 'lib/paintbrush_support/color_element.rb', line 23

def inspect
  "<#{self.class.name} index=#{index} code=#{code}>"
end

#to_sObject



19
20
21
# File 'lib/paintbrush_support/color_element.rb', line 19

def to_s
  "#{Escapes.open(index)}#{string}#{Escapes.close(index)}"
end