Class: Cogger::Formatters::Parsers::Position

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

Overview

Parses template and reorders attributes based on template key positions.

Constant Summary collapse

PATTERN =
/
  %             # Start.
  ?             # Flag, width, or precision.
  <             # Reference start.
  (?<name>\w+)  # Name.
  (?::[\w]+)?   # Optional delimiter and directive.
  >             # Reference end.
  ?             # Specifier.
/x

Instance Method Summary collapse

Constructor Details

#initialize(pattern: PATTERN) ⇒ Position

Returns a new instance of Position.



18
19
20
# File 'lib/cogger/formatters/parsers/position.rb', line 18

def initialize pattern: PATTERN
  @pattern = pattern
end

Instance Method Details

#call(template, attributes) ⇒ Object

:reek:FeatureEnvy



23
24
25
26
27
28
29
# File 'lib/cogger/formatters/parsers/position.rb', line 23

def call template, attributes
  return attributes if !template || template.empty?
  return attributes unless template.match? pattern

  keys = scan template
  attributes.slice(*keys).merge!(attributes.except(*keys))
end