<commit_before>MetricFu.metrics_require   { 'saikuro/parsing_element' }
module MetricFu
  class SaikuroScratchFile

    def self.assemble_files(glob)
      files = []
      glob.each do |path|
        if is_valid_text_file?(path)
          file = new(path)
          if file
            files << file
          end
        end
      end
      files
    end

    attr_reader :elements

    def initialize(path)
      @path = path
      @elements = []
      File.open(@path, "r") do |file|
        get_elements(file)
      end
    end

    def self.is_valid_text_file?(path)
      File.open(path, "r") do |file|
        if file.eof? || !file.readline.match(/--/)
          return false
        else
          return true<commit_msg>Open files in BINARY to avoid encoding issues<commit_after>MetricFu.metrics_require   { 'saikuro/parsing_element' }
module MetricFu
  class SaikuroScratchFile

    def self.assemble_files(glob)
      files = []
      glob.each do |path|
        if is_valid_text_file?(path)
          file = new(path)
          if file
            files << file
          end
        end
      end
      files
    end

    attr_reader :elements

    def initialize(path)
      @path = path
      @elements = []
      File.open(@path, "rb") do |file|
        get_elements(file)
      end
    end

    def self.is_valid_text_file?(path)
      File.open(path, "rb") do |file|
        if file.eof? || !file.readline.match(/--/)
          return false
        else
          return true
{'fraction_non_alphanumeric': 0.09504685408299866, 'fraction_numerical': 0.0, 'mean_word_length': 1.789179104477612, 'pattern_counts': {'":': 0, '<': 7, '<?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': '6806456', 'n_tokens_mistral': 478, 'n_tokens_neox': 469, 'n_words': 112}