<commit_before>module NyanCatFormat
  module Music
  
    MUSIC_LENGTH = 27.06 # seconds

    def osx?
      platform.downcase.include?("darwin")
    end

    def linux?
      platform.downcase.include?('linux')
    end

    def kernel=(kernel)
      @kernel = kernel
    end

    def kernel
      @kernel ||= Kernel
    end

    def platform=(platform)
      @platform = platform
    end

    def platform
      @platform ||= RUBY_PLATFORM
    end

    def nyan_mp3
      File.expand_path('../../../data/nyan-cat.mp3', __FILE__)
    end

    def start input
      super
      t = Thread.new do
        loop do
          if osx?
            kernel.system("afplay #{nyan_mp3} &")
          elsif linux?
            play_on_linux
          end
          Thread.current["started_playing"] ||= true
          sleep MUSIC_LENGTH
        end
      end
      until t["started_playing"]
        sleep 0.001
      end
    end

    def kill_music
      if File.exists? nyan_mp3
        if osx?
          system("killall -9 afplay &>/dev/null")
        elsif linux?
          kill_music_on_linux
        end
      end
    end

    def dump_summary(duration, example_count, failure_count, pending_count)
      kill_music
      super
    end
    
    private

    def play_on_linux
      kernel.system("[ -e #{nyan_mp3} ] && type mpg321 &>/dev/null && mpg321 #{nyan_mp3} &>/dev/null &") if kernel.system('which mpg321 &>/dev/null && type mpg321 &>/dev/null')
      kernel.system("[ -e #{nyan_mp3} ] && type mpg123 &>/dev/null && mpg123 #{nyan_mp3} &>/dev/null &") if kernel.system('which mpg123 &>/dev/null && type mpg123 &>/dev/null')
    end

    def kill_music_on_linux
      system("killall -9 mpg321 &>/dev/null") if kernel.system("which mpg321 &>/dev/null && type mpg321 &>/dev/null")
      system("killall -9 mpg123 &>/dev/null") if kernel.system("which mpg123 &>/dev/null && type mpg123 &>/dev/null")
    end

  end
end<commit_msg>Makes dump_summary work for rspec2 and rspec3<commit_after>module NyanCatFormat
  module Music

    MUSIC_LENGTH = 27.06 # seconds

    def osx?
      platform.downcase.include?("darwin")
    end

    def linux?
      platform.downcase.include?('linux')
    end

    def kernel=(kernel)
      @kernel = kernel
    end

    def kernel
      @kernel ||= Kernel
    end

    def platform=(platform)
      @platform = platform
    end

    def platform
      @platform ||= RUBY_PLATFORM
    end

    def nyan_mp3
      File.expand_path('../../../data/nyan-cat.mp3', __FILE__)
    end

    def start input
      super
      t = Thread.new do
        loop do
          if osx?
            kernel.system("afplay #{nyan_mp3} &")
          elsif linux?
            play_on_linux
          end
          Thread.current["started_playing"] ||= true
          sleep MUSIC_LENGTH
        end
      end
      until t["started_playing"]
        sleep 0.001
      end
    end

    def kill_music
      if File.exists? nyan_mp3
        if osx?
          system("killall -9 afplay &>/dev/null")
        elsif linux?
          kill_music_on_linux
        end
      end
    end

    def dump_summary(*args)
      kill_music
      super
    end

    private

    def play_on_linux
      kernel.system("[ -e #{nyan_mp3} ] && type mpg321 &>/dev/null && mpg321 #{nyan_mp3} &>/dev/null &") if kernel.system('which mpg321 &>/dev/null && type mpg321 &>/dev/null')
      kernel.system("[ -e #{nyan_mp3} ] && type mpg123 &>/dev/null && mpg123 #{nyan_mp3} &>/dev/null &") if kernel.system('which mpg123 &>/dev/null && type mpg123 &>/dev/null')
    end

    def kill_music_on_linux
      system("killall -9 mpg321 &>/dev/null") if kernel.system("which mpg321 &>/dev/null && type mpg321 &>/dev/null")
      system("killall -9 mpg123 &>/dev/null") if kernel.system("which mpg123 &>/dev/null && type mpg123 &>/dev/null")
    end

  end
end
{'fraction_non_alphanumeric': 0.1216710182767624, 'fraction_numerical': 0.03237597911227154, 'mean_word_length': 2.035657686212361, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6512057', 'n_tokens_mistral': 1384, 'n_tokens_neox': 1264, 'n_words': 316}