<commit_before># encoding: utf-8

module Github
  # Request arguments handler
  class Arguments

    include Normalizer
    include ParameterFilter
    include Validations

    # Arguments used to construct request path
    #
    attr_reader :arguments

    # Parameters passed to request
    attr_reader :params

    # The request api
    #
    attr_reader :api

    # Required arguments
    #
    attr_reader :args_required
    private :args_required

    # Allowed keys inside parameter hash
    #
    attr_reader :filter
    private :filter

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

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

      if args.any?
        parse_arguments *args
      else
        # Arguments are inside the parameters hash
        parse_options options
      end
      filter!(filter, options) if filter
      @params = options
      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 args_required[indx], arg
      end
      check_requirement!(*args)
    end<commit_msg>Add ability to filter and assert required keys when parsing arguments.<commit_after># encoding: utf-8

module Github
  # Request arguments handler
  class Arguments

    include Normalizer
    include ParameterFilter
    include Validations

    # Arguments used to construct request path
    #
    attr_reader :arguments

    # Parameters passed to request
    attr_reader :params

    # The request api
    #
    attr_reader :api

    # Required arguments
    #
    attr_reader :args_required
    private :args_required

    # Takes api, filters and required arguments
    #
    # = Parameters
    #  :args_required - arguments that must be present before request is fired
    #
    def initialize(api, options={})
      normalize! options
      @api           = api
      @args_required = options.fetch('args_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)
      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 self if block_given?
      self
    end

    def sift(keys)
      filter! keys, params if keys.any?
      self
    end

    def assert_required(required)
      assert_required_keys required, 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 args_required[indx], arg
      end
      check_requirement!(*args)
    end
{'fraction_non_alphanumeric': 0.059831542259657276, 'fraction_numerical': 0.0005808887598024978, 'mean_word_length': 2.3307543520309477, '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': '3487167', 'n_tokens_mistral': 943, 'n_tokens_neox': 917, 'n_words': 319}