Class: Cogger::Formatters::Parsers::Key

Inherits:
Abstract
  • Object
show all
Defined in:
lib/cogger/formatters/parsers/key.rb

Overview

Parses template for specific and dynamic keys (i.e. string format specifiers).

Constant Summary collapse

PATTERN =
/
  %                                   # Start.
  (?<flag>[\s#+-0*])?                 # Optional flag.
  \.?                                 # Optional precision.
  (?<width>\d+)?                      # Optional width.
  <                                   # Reference start.
  (?<key>\w+)                         # Key.
  :                                   # Delimiter.
  (?<directive>\w+)                   # Directive.
  >                                   # Reference end.
  (?<specifier>[ABEGXabcdefgiopsux])  # Specifier.
/x

Constants inherited from Abstract

Abstract::NEW_LINE, Abstract::SANITIZERS

Instance Method Summary collapse

Constructor Details

#initialize(pattern: PATTERN) ⇒ Key

Returns a new instance of Key.



23
24
25
26
# File 'lib/cogger/formatters/parsers/key.rb', line 23

def initialize pattern: PATTERN
  super()
  @pattern = pattern
end

Instance Method Details

#call(template, level) ⇒ Object



28
29
30
31
# File 'lib/cogger/formatters/parsers/key.rb', line 28

def call template, level
  mutate template, level
  template
end