Class: Tone::Decoder

Inherits:
Object
  • Object
show all
Defined in:
lib/tone/decoder.rb

Overview

Decodes color encoded text into metadata (hash).

Constant Summary collapse

PATTERN =
/
  \e\[              # Start.
  (?<codes>[\d;]+)  # Style codes.
  m                 # Start suffix.
  (?<text>.+?)      # Lazy text.
  \e\[0m            # Stop.
/mx

Instance Method Summary collapse

Constructor Details

#initialize(pattern: PATTERN, defaults: DEFAULTS, client: StringScanner) ⇒ Decoder

Returns a new instance of Decoder.



16
17
18
19
20
21
# File 'lib/tone/decoder.rb', line 16

def initialize pattern: PATTERN, defaults: DEFAULTS, client: StringScanner
  @pattern = pattern
  @defaults = defaults
  @client = client
  @prefix_pattern = /.*#{pattern}/m
end

Instance Method Details

#call(text) ⇒ Object



23
# File 'lib/tone/decoder.rb', line 23

def call(text) = scan client.new(text.to_s)