<commit_before># Used to find translations in the Rails app by inspecting .erb- and .haml-files.
class AwesomeTranslations::ErbInspector
  AutoAutoloader.autoload_sub_classes(self, __FILE__)

  def initialize(args = {})
    @args = args
    @args[:exts] ||= [".erb", ".haml", ".rb", ".rake"]

    if @args[:dirs]
      @dirs = @args[:dirs]
    else
      @dirs = AwesomeTranslations.config.paths_to_translate
    end
  end

  # Yields all relevant .erb- and .haml-files.
  def files
    Enumerator.new do |yielder|
      @dirs.each do |dir|
        scan_dir("", dir, yielder)
      end
    end
  end

  def file(root_path, file_path)
    AwesomeTranslations::ErbInspector::FileInspector.new(
      file_path: file_path,
      root_path: root_path
    )
  end

private

  def scan_dir(path, root_path, yielder)
    Dir.foreach("#{root_path}/#{path}") do |file|
      next if file == "." || file == ".."
      file_path = path.to_s
      file_path << "/" unless file_path.empty?
      file_path << file

      full_path = "#{root_path}/#{file_path}"
      ext = File.extname(file_path)

      if File.directory?(full_path)
        scan_dir(file_path, root_path, yielder)
      elsif @args[:exts].include?(ext)<commit_msg>Fixed issue where path-variable was changed<commit_after># Used to find translations in the Rails app by inspecting .erb- and .haml-files.
class AwesomeTranslations::ErbInspector
  AutoAutoloader.autoload_sub_classes(self, __FILE__)

  def initialize(args = {})
    @args = args
    @args[:exts] ||= [".erb", ".haml", ".rb", ".rake"]

    if @args[:dirs]
      @dirs = @args[:dirs]
    else
      @dirs = AwesomeTranslations.config.paths_to_translate
    end
  end

  # Yields all relevant .erb- and .haml-files.
  def files
    Enumerator.new do |yielder|
      @dirs.each do |dir|
        scan_dir("", dir, yielder)
      end
    end
  end

  def file(root_path, file_path)
    AwesomeTranslations::ErbInspector::FileInspector.new(
      file_path: file_path,
      root_path: root_path
    )
  end

private

  def scan_dir(path, root_path, yielder)
    Dir.foreach("#{root_path}/#{path}") do |file|
      next if file == "." || file == ".."
      file_path = path.clone
      file_path << "/" unless file_path.empty?
      file_path << file

      full_path = "#{root_path}/#{file_path}"
      ext = File.extname(file_path)

      if File.directory?(full_path)
        scan_dir(file_path, root_path, yielder)
      elsif @args[:exts].include?(ext)
{'fraction_non_alphanumeric': 0.1332523288780883, 'fraction_numerical': 0.0, 'mean_word_length': 2.9268680445151034, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3941631', 'n_tokens_mistral': 896, 'n_tokens_neox': 872, 'n_words': 194}