<commit_before># encoding: utf-8

module Github
  # Request arguments handler
  class Arguments

    include Normalizer
    include ParameterFilter
    include Validations

    # Parameters passed to request
    attr_reader :params

    # The request api
    #
    attr_reader :api

    # Required arguments
    #
    attr_reader :required
    private :required

    # Takes api, filters and required arguments
    #
    # = Parameters
    #  :required - arguments that must be present before request is fired
    #
    def initialize(api, options={})
      normalize! options
      @api      = api
      @required = options.fetch('required', []).map(&:to_s)
    end

    # Parse arguments to allow for flexible api calls.
    # Arguments can be part of parameters hash or be simple string arguments.
    #
    def parse(*args, &block)
      options = args.extract_options!
      normalize! options

      if args.any?
        parse_arguments *args
      else
        # Arguments are inside the parameters hash
        parse_options options
      end
      @params = options
      yield_or_eval(&block)
      self
    end

    # Remove unkown parameters.
    #
    # = Parameters
    #  :recursive - boolean that toggles whether nested filtering should be applied
    #
    def sift(keys, options={})
      filter! keys, params, options if keys.any?
      self
    end

    # Check if required parameters are present.
    #
    def assert_required(required)
      assert_required_keys required, params
      self
    end

    # Check if parameters match expected values.
    #
    def assert_values(values)
      assert_valid_values values, params
      self
    end

    private

    # Check and set all requried arguments.
    #
    def parse_arguments(*args)
      assert_presence_of *args
      args.each_with_index do |arg, indx|
        api.set required[indx], arg
      end
      check_requirement!(*args)
    end

    # Remove required arguments from parameters and
    # validate their presence(if not nil or empty string).
    #
    def parse_options(options)
      options.each { |key, val| remove_required options, key, val }
      check_assignment!(options)
    end

    # Remove required argument from parameters
    #
    def remove_required(options, key, val)<commit_msg>Allow for filtering parts of parameters hash.<commit_after># encoding: utf-8

module Github
  # Request arguments handler
  class Arguments

    include Normalizer
    include ParameterFilter
    include Validations

    # Parameters passed to request
    attr_reader :params

    # The request api
    #
    attr_reader :api

    # Required arguments
    #
    attr_reader :required
    private :required

    # Takes api, filters and required arguments
    #
    # = Parameters
    #  :required - arguments that must be present before request is fired
    #
    def initialize(api, options={})
      normalize! options
      @api      = api
      @required = options.fetch('required', []).map(&:to_s)
    end

    # Parse arguments to allow for flexible api calls.
    # Arguments can be part of parameters hash or be simple string arguments.
    #
    def parse(*args, &block)
      options = args.extract_options!
      normalize! options

      if args.any?
        parse_arguments *args
      else
        # Arguments are inside the parameters hash
        parse_options options
      end
      @params = options
      yield_or_eval(&block)
      self
    end

    # Remove unkown parameters.
    #
    # = Parameters
    #  :recursive - boolean that toggles whether nested filtering should be applied
    #
    def sift(keys, key=nil, options={})
      filter! keys, (key.nil? ? params : params[key]), options if keys.any?
      self
    end

    # Check if required parameters are present.
    #
    def assert_required(required)
      assert_required_keys required, params
      self
    end

    # Check if parameters match expected values.
    #
    def assert_values(values, key=nil)
      assert_valid_values values, (key.nil? ? params : params[key])
      self
    end

    private

    # Check and set all requried arguments.
    #
    def parse_arguments(*args)
      assert_presence_of *args
      args.each_with_index do |arg, indx|
        api.set required[indx], arg
      end
      check_requirement!(*args)
    end

    # Remove required arguments from parameters and
    # validate their presence(if not nil or empty string).
    #
    def parse_options(options)
      options.each { |key, val| remove_required options, key, val }
      check_assignment!(options)
    end

    # Remove required argument from parameters
    #
    def remove_required(options, key, val)
{'fraction_non_alphanumeric': 0.06776400171013254, 'fraction_numerical': 0.00042753313381787086, 'mean_word_length': 2.4153284671532846, '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': '489088', 'n_tokens_mistral': 1291, 'n_tokens_neox': 1258, 'n_words': 437}