<commit_before># frozen_string_literal: true

require 'json'

module RRJ
  # @author VAILLANT Jeremy <<EMAIL>>
  # Response Janus received to RabbitMQ server
  class ResponseJanus
    def initialize(channel, connection, logs, opts = {})
      @channel = channel
      @connection = connection
      @opts = opts
      @logs = logs
    end

    # Read a response to janus (in RabbitMQ queue)
    # @return [Hash] resultat to request
    def read(queue_from)
      option_sub = { block: true, manual_ack: false, exclusive: false }
      the_queue = @channel.queue(queue_from)
      the_queue.subscribe(option_sub) do |info, prop, pay|
        listen(info, prop, pay)
      end
      return_response_json
    end

    private

    # Listen a response to queue
    def listen(_delivery_info, properties, payload)
      if @opts['correlation'] == properties[:correlation_id]
        @response = payload
        @connection.close
      end
    end

    def return_response_json
      @response = JSON.parse(@response)
      case @opts['janus']
      when 'create'
        merge('session_id')
      when 'attach'
        merge('handle_id')
      end
      @logs.debug @response
      @response
    end

    def resp
      @response['data']['id']
    end

    def merge(key)
      @responser[key] = resp
    end
  end
end<commit_msg>Fix syntax varaible<commit_after># frozen_string_literal: true

require 'json'

module RRJ
  # @author <NAME> <<EMAIL>>
  # Response Janus received to RabbitMQ server
  class ResponseJanus
    def initialize(channel, connection, logs, opts = {})
      @channel = channel
      @connection = connection
      @opts = opts
      @logs = logs
    end

    # Read a response to janus (in RabbitMQ queue)
    # @return [Hash] resultat to request
    def read(queue_from)
      option_sub = { block: true, manual_ack: false, exclusive: false }
      the_queue = @channel.queue(queue_from)
      the_queue.subscribe(option_sub) do |info, prop, pay|
        listen(info, prop, pay)
      end
      return_response_json
    end

    private

    # Listen a response to queue
    def listen(_delivery_info, properties, payload)
      if @opts['correlation'] == properties[:correlation_id]
        @response = payload
        @connection.close
      end
    end

    def return_response_json
      @response = JSON.parse(@response)
      case @opts['janus']
      when 'create'
        merge('session_id')
      when 'attach'
        merge('handle_id')
      end
      @logs.debug @response
      @response
    end

    def resp
      @response['data']['id']
    end

    def merge(key)
      @response[key] = resp
    end
  end
end
{'fraction_non_alphanumeric': 0.0944822373393802, 'fraction_numerical': 0.0, 'mean_word_length': 2.501322751322751, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '1650033', 'n_tokens_mistral': 802, 'n_tokens_neox': 775, 'n_words': 228}