Class: I18n::Processes::Scanners::PatternMapper

Inherits:
FileScanner show all
Includes:
OccurrenceFromPosition, RelativeKeys, RubyKeyLiterals
Defined in:
lib/i18n/processes/scanners/pattern_mapper.rb

Overview

Maps the provided patterns to keys.

Constant Summary

Constants included from RubyKeyLiterals

RubyKeyLiterals::LITERAL_RE, RubyKeyLiterals::VALID_KEY_CHARS, RubyKeyLiterals::VALID_KEY_RE

Instance Attribute Summary

Attributes inherited from FileScanner

#config

Instance Method Summary collapse

Methods included from RubyKeyLiterals

#literal_re, #strip_literal, #valid_key?

Methods included from OccurrenceFromPosition

#occurrence_from_position

Methods included from RelativeKeys

#absolute_key

Methods inherited from FileScanner

#keys

Methods inherited from Scanner

#keys

Constructor Details

#initialize(config:, **args) ⇒ PatternMapper

Returns a new instance of PatternMapper.

Parameters:

  • patterns (Array<[String, String]> the list of pattern-key pairs the patterns follow the regular expression syntax, with a syntax addition for matching string/symbol literals: you can include %{key} in the pattern, and it will be converted to a named capture group, capturing ruby strings and symbols, that can then be used in the key: patterns: [['Spree\.t[( ]\s*%{key}', 'spree.%{key}']] All of the named capture groups are interpolated into the key with %{group_name} interpolations.)

    atterns [Array<[String, String]> the list of pattern-key pairs the patterns follow the regular expression syntax, with a syntax addition for matching string/symbol literals: you can include %key in the pattern, and it will be converted to a named capture group, capturing ruby strings and symbols, that can then be used in the key:

    patterns: [['Spree\.t[( ]\s*%{key}', 'spree.%{key}']]
    

    All of the named capture groups are interpolated into the key with %group_name interpolations.



24
25
26
27
# File 'lib/i18n/processes/scanners/pattern_mapper.rb', line 24

def initialize(config:, **args)
  super
  @patterns = configure_patterns(config[:patterns] || [])
end