Class: I18n::Tasks::Scanners::FileScanner Abstract
- 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.
Direct Known Subclasses
Instance Attribute Summary collapse
- #config ⇒ Object readonly
Instance Method Summary collapse
-
#initialize(config: {}, file_finder_provider: Files::CachingFileFinderProvider.new, file_reader: Files::CachingFileReader.new) ⇒ FileScanner
constructor
A new instance of FileScanner.
-
#keys ⇒ Array<Results::KeyOccurrences>
The keys found by this scanner and their occurrences.
Constructor Details
#initialize(config: {}, file_finder_provider: Files::CachingFileFinderProvider.new, file_reader: Files::CachingFileReader.new) ⇒ FileScanner
Returns a new instance of FileScanner.
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
#config ⇒ Object (readonly)
11 12 13 |
# File 'lib/i18n/tasks/scanners/file_scanner.rb', line 11 def config @config end |
Instance Method Details
#keys ⇒ Array<Results::KeyOccurrences>
Returns the keys found by this scanner and their occurrences.
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 |