Class: I18n::Tasks::Scanners::PatternScanner

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

Overview

Scan for I18n.t usages using a simple regular expression.

Direct Known Subclasses

PatternWithScopeScanner

Constant Summary collapse

TRANSLATE_CALL_RE =
/(?<=^|[^\w'\-.]|[^\w'-]I18n\.|I18n\.)t(?:!|ranslate!?)?/.freeze
IGNORE_LINES =
{
  'coffee' => /^\s*#(?!\si18n-tasks-use)/,
  'erb' => /^\s*<%\s*#(?!\si18n-tasks-use)/,
  'es6' => %r{^\s*//(?!\si18n-tasks-use)},
  'haml' => /^\s*-\s*#(?!\si18n-tasks-use)/,
  'js' => %r{^\s*//(?!\si18n-tasks-use)},
  'opal' => /^\s*#(?!\si18n-tasks-use)/,
  'slim' => %r{^\s*(?:-#|/)(?!\si18n-tasks-use)}
}.freeze

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

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(**args) ⇒ PatternScanner

Returns a new instance of PatternScanner.



26
27
28
29
30
31
32
33
# File 'lib/i18n/tasks/scanners/pattern_scanner.rb', line 26

def initialize(**args)
  super
  @translate_call_re = config[:translate_call].present? ? Regexp.new(config[:translate_call]) : TRANSLATE_CALL_RE
  @pattern = config[:pattern].present? ? Regexp.new(config[:pattern]) : default_pattern
  @ignore_lines_res = (config[:ignore_lines] || IGNORE_LINES).each_with_object({}) do |(ext, re), h|
    h[ext.to_s] = Regexp.new(re)
  end
end