<commit_before>module TRecs
  class Recorder
    attr_reader :writer
    attr_reader :strategy
    attr_reader :step
    attr_reader :recording
    attr_reader :current_time
    attr_reader :current_content

    attr_accessor :offset

    def initialize(options={})
      @writer   = options.fetch(:writer)
      @writer.recorder = self

      @strategy = options.fetch(:strategy)
      @strategy.recorder = self

      @step = options.fetch(:step) { 100 }
      @offset = options.fetch(:offset) { 0 }
      @recording = false
      @current_time = nil
    end

    def record
      self.current_time = nil
      self.recording = true
      writer.setup
      strategy.perform
      writer.render
      self.recording = false
    end

    def current_frame(options={})
      time = options.fetch(:time) { next_timestamp }
      content = options.fetch(:content)
      @current_time = time
      @current_content = content

      if @previous_content != content
        new_current_time = current_time + offset
        writer.create_frame(time: new_current_time, content: current_content)
        @previous_content = content
      end
    end

    def next_timestamp
      @current_time = -step unless @current_time
      @current_time += step
    end

    def stop
      strategy.stop
    end

    private
    attr_writer :recording
    attr_writer :current_time
    attr_writer :current_content

  end
end<commit_msg>Refactored recorder<commit_after>module TRecs
  class Recorder
    attr_reader :writer
    attr_reader :strategy
    attr_reader :step
    attr_reader :recording
    attr_reader :current_time
    attr_reader :current_content

    attr_accessor :offset

    def initialize(options={})
      @writer          = options.fetch(:writer)
      @writer.recorder = self

      @strategy          = options.fetch(:strategy)
      @strategy.recorder = self

      @step   = options.fetch(:step)   { 100 }
      @offset = options.fetch(:offset) { 0 }

      @recording    = false
      @current_time = nil
    end

    def record
      do_record do
        writer.setup
        strategy.perform
        writer.render
      end
    end

    def current_frame(options={})
      time    = options.fetch(:time) { next_timestamp }
      content = options.fetch(:content)
      
      @current_time    = time
      @current_content = content

      if @previous_content != content
        new_current_time  = current_time + offset
        writer.create_frame(time: new_current_time, content: current_content)
        @previous_content = content
      end
    end

    def next_timestamp
      @current_time = -step unless @current_time
      @current_time += step
    end

    def stop
      strategy.stop
    end

    private
    attr_writer :recording
    attr_writer :current_time
    attr_writer :current_content

    def do_record
      self.current_time = nil
      self.recording    = true
      yield
      self.recording    = false
    end

  end
end
{'fraction_non_alphanumeric': 0.0722972972972973, 'fraction_numerical': 0.002702702702702703, 'mean_word_length': 2.3120805369127515, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6235172', 'n_tokens_mistral': 877, 'n_tokens_neox': 847, 'n_words': 203}