Class: TTYString::Style
- Inherits:
-
Object
- Object
- TTYString::Style
- Defined in:
- lib/tty_string/style.rb
Overview
rubocop:disable Metrics/ClassLength
Instance Attribute Summary collapse
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
Instance Method Summary collapse
-
#initialize(style_codes = ['0'], parser:, properties: {}) ⇒ Style
constructor
A new instance of Style.
- #new(style_codes) ⇒ Object
- #to_s(context:) ⇒ Object
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
#properties ⇒ Object (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 |