Class: I18n::Tasks::Scanners::FileScanner Abstract

Inherits:
Scanner
  • Object
show all
Defined in:
lib/i18n/tasks/scanners/file_scanner.rb

Overview

This class is abstract.

The child must implement #scan_file.

A base class for a scanner that analyses files.

Since:

  • 0.9.0

Direct Known Subclasses

PatternMapper, PatternScanner, RubyAstScanner

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config: {}, file_finder_provider: Files::CachingFileFinderProvider.new, file_reader: Files::CachingFileReader.new) ⇒ FileScanner

Returns a new instance of FileScanner.

Since:

  • 0.9.0



13
14
15
16
17
18
19
20
21
22
# File 'lib/i18n/tasks/scanners/file_scanner.rb', line 13

def initialize(
  config: {},
  file_finder_provider: Files::CachingFileFinderProvider.new,
  file_reader: Files::CachingFileReader.new
)
  super()
  @config      = config
  @file_reader = file_reader
  @file_finder = file_finder_provider.get(**config.slice(:paths, :only, :exclude))
end

Instance Attribute Details

#configObject (readonly)

Since:

  • 0.9.0



11
12
13
# File 'lib/i18n/tasks/scanners/file_scanner.rb', line 11

def config
  @config
end

Instance Method Details

#keysArray<Results::KeyOccurrences>

Returns the keys found by this scanner and their occurrences.

Returns:

Since:

  • 0.9.0



25
26
27
28
29
30
31
# File 'lib/i18n/tasks/scanners/file_scanner.rb', line 25

def keys
  (traverse_files do |path|
    scan_file(path)
  end.reduce(:+) || []).group_by(&:first).map do |key, keys_occurrences|
    Results::KeyOccurrences.new(key: key, occurrences: keys_occurrences.map(&:second))
  end
end