Class: TTYString::Style

Inherits:
Object
  • Object
show all
Defined in:
lib/tty_string/style.rb

Overview

rubocop:disable Metrics/ClassLength

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(style_codes = ['0'], parser:, properties: {}) ⇒ Style

Returns a new instance of Style.



7
8
9
10
11
# File 'lib/tty_string/style.rb', line 7

def initialize(style_codes = ['0'], parser:, properties: {})
  @properties = properties.dup
  @parser = parser
  parse_code(style_codes)
end

Instance Attribute Details

#propertiesObject (readonly)

Returns the value of attribute properties.



5
6
7
# File 'lib/tty_string/style.rb', line 5

def properties
  @properties
end

Instance Method Details

#new(style_codes) ⇒ Object



13
14
15
# File 'lib/tty_string/style.rb', line 13

def new(style_codes)
  self.class.new(style_codes, properties: properties, parser: parser)
end

#to_s(context:) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/tty_string/style.rb', line 17

def to_s(context:)
  return '' if self == context

  values = properties.map { |k, v| v if context.properties[k] != v }.compact.uniq
  return '' if values.empty?

  "\e[#{values.join(';')}m"
end