<commit_before>module Pair
  class Client
    attr_reader :pair

    include EM::ZeroMQ::EventEmitter

    def initialize(pair, timeout = 60)
      @pair, @timeout = pair, timeout
      @connected = false

      ping

      @pair.on(:message) { |part1, part2|
        @connected ||= begin
          emit(:connected)
          setup_activity_check
          true
        end

        reset_activity

        case (method = part1.copy_out_string)
        when "ping"
          pong
        when "pong" # NOOP
        when "pair:shutdown"
          terminate(0)
        else
          # TODO
          emit(:message, method, part2.copy_out_string)
        end
      }
    end

    def terminate(time_since_activity)
      @activity_check.cancel if @activity_check
      @connected = false
      emit(:disconnected, time_since_activity)
    end

    def send(method, body = nil)
      @pair.send_msg(method, body)
    end

    private

    def ping
      send("ping")
    end

    def pong
      send("pong")<commit_msg>Switch to pair:ping and pair:pong<commit_after>module Pair
  class Client
    attr_reader :pair

    include EM::ZeroMQ::EventEmitter

    def initialize(pair, timeout = 60)
      @pair, @timeout = pair, timeout
      @connected = false

      ping

      @pair.on(:message) { |part1, part2|
        @connected ||= begin
          emit(:connected)
          setup_activity_check
          true
        end

        reset_activity

        case (method = part1.copy_out_string)
        when "pair:ping", "ping"
          pong
        when "pair:pong", "pong" # NOOP
        when "pair:shutdown"
          terminate(0)
        else
          # TODO
          emit(:message, method, part2.copy_out_string)
        end
      }
    end

    def terminate(time_since_activity)
      @activity_check.cancel if @activity_check
      @connected = false
      emit(:disconnected, time_since_activity)
    end

    def send(method, body = nil)
      @pair.send_msg(method, body)
    end

    private

    def ping
      send("ping")
    end

    def pong
      send("pong")
{'fraction_non_alphanumeric': 0.08662175168431184, 'fraction_numerical': 0.006737247353224254, 'mean_word_length': 1.883495145631068, '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': '2439820', 'n_tokens_mistral': 647, 'n_tokens_neox': 612, 'n_words': 151}