<commit_before>module Octopusci
  class IO
    attr_accessor :job

    def initialize(job)
      @job = job
    end

    def read_all_out
      if File.exists?(abs_output_file_path)
        return File.open(abs_output_file_path, 'r').read()
      else
        return ""
      end
    end

    def read_all_log
      if File.exists?(abs_log_file_path)
        return File.open(abs_log_file_path, 'r').read()
      else
        return ""
      end
    end

    def write_out(msg="", &block)
      write_raw_output(false, msg, &block)
    end

    def write_log(msg="", &block)
      write_raw_output(true, msg, &block)
    end

    private

    def write_raw_output(silently=false, msg="")
      # Make sure that the directory structure is in place for the job output.
      if !File.directory?(self.abs_output_base_path)
        FileUtils.mkdir_p(self.abs_output_base_path)
      end
      
      # Run the command and output the output to the job file
      out_f = if silently
        File.open(self.abs_log_file_path, 'a')
      else
        File.open(self.abs_output_file_path, 'a')
      end

      yield(out_f) if block_given?
      out_f << msg unless msg.nil? || msg.empty?

      out_f.close
    end

    def abs_output_file_path
      return "#{abs_output_base_path}/output.txt"
    end<commit_msg>Cleaned up IO a bit to use private methods correctly.<commit_after>module Octopusci
  class IO
    attr_accessor :job

    def initialize(job)
      @job = job
    end

    def read_all_out
      if File.exists?(abs_output_file_path)
        cont = ""
        File.open(abs_output_file_path, 'r') do |f|
          cont = f.read()
        end
        return cont
      else
        return ""
      end
    end

    def read_all_log
      if File.exists?(abs_log_file_path)
        return File.open(abs_log_file_path, 'r').read()
      else
        return ""
      end
    end

    def write_out(msg="", &block)
      write_raw_output(false, msg, &block)
    end

    def write_log(msg="", &block)
      write_raw_output(true, msg, &block)
    end

    def write_raw_output(silently=false, msg="")
      # Make sure that the directory structure is in place for the job output.
      if !File.directory?(abs_output_base_path)
        FileUtils.mkdir_p(abs_output_base_path)
      end
      
      # Run the command and output the output to the job file
      out_f = if silently
        File.open(abs_log_file_path, 'a')
      else
        File.open(abs_output_file_path, 'a')
      end

      yield(out_f) if block_given?
      out_f << msg unless msg.nil? || msg.empty?

      out_f.close
    end

    private

    def abs_output_file_path
      return "#{abs_output_base_path}/output.txt"
    end
{'fraction_non_alphanumeric': 0.08694043655197928, 'fraction_numerical': 0.0, 'mean_word_length': 2.261761158021713, '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': '3784077', 'n_tokens_mistral': 908, 'n_tokens_neox': 887, 'n_words': 221}