Class: Concolor::String

Inherits:
Object
  • Object
show all
Defined in:
lib/concolor/string.rb

Overview

Extension module for String class

Since:

  • 1.0.1

Instance Method Summary collapse

Constructor Details

#initialize(str = '', options: []) ⇒ String

Returns a new instance of String.

Parameters:

  • str (String) (defaults to: '')

    some string object

  • options (Array<Symbol>) (defaults to: [])

Since:

  • 1.0.1



10
11
12
13
14
15
16
17
18
19
# File 'lib/concolor/string.rb', line 10

def initialize(str = '', options: [])
  @str = str
  parsed = parse_options!(options)

  @color = ::Concolor::Mappers::COLORS[parsed[:colors].first]
  @bg_color = ::Concolor::Mappers::BG_COLORS[parsed[:bg_colors].first]
  @modes = parsed[:modes].map do |mode|
    Concolor::Mappers::MODES[mode]
  end
end

Instance Method Details

#to_sString Also known as: inspect

To string

Returns:

Since:

  • 1.0.1



24
25
26
# File 'lib/concolor/string.rb', line 24

def to_s
  "\033[#{style}m#{@str}\033[0m"
end