Class: Cogger::Formatters::Parsers::Universal

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

Overview

Sanitizes and extracts the universal directive a template.

Constant Summary collapse

PATTERN =

rubocop:todo Lint/MixedRegexpCaptureTypes

%r(
  (                  # Conditional start.
  \A                 # Search start.
  <                  # Tag start.
  (?<directive>\w+)  # Directive.
  >                  # Tag end.
  |                  # Conditional pipe.
  <                  # Tag start.
  /                  # Tag close.
  (?<directive>\w+)  # Directive.
  >                  # Tag end.
  \Z                 # Search end.
  )                  # Conditional end.
)mx
KEY =

rubocop:enable Lint/MixedRegexpCaptureTypes

"directive"

Instance Method Summary collapse

Constructor Details

#initialize(pattern: PATTERN, key: KEY) ⇒ Universal

Returns a new instance of Universal.



29
30
31
32
# File 'lib/cogger/formatters/parsers/universal.rb', line 29

def initialize pattern: PATTERN, key: KEY
  @pattern = pattern
  @key = key
end

Instance Method Details

#call(template) ⇒ Object



34
35
36
37
38
# File 'lib/cogger/formatters/parsers/universal.rb', line 34

def call template
  return template unless template.match? pattern

  [template.gsub(pattern, Core::EMPTY_STRING), template.match(pattern)[key]]
end