<commit_before>module CMIS
  class Children

    def initialize(folder, options)
      options.stringify_keys!

      @folder = folder
      @repository = folder.repository
      @connection = folder.repository.connection

      @max_items = options['max_items'] || 10
      @skip_count = options['skip_count'] || 0
      @order_by = options['order_by']

      @has_next = true
    end

    def next_results
      result = do_get_children

      @skip_count += result.results.size
      @has_next = result.has_more_items
      @total = result.num_items

      result.results
    end

    def has_next?
      @has_next
    end

    def total
      @total ||= do_get_children.num_items
    end

    private

    def do_get_children
      result = @connection.execute!({ cmisselector: 'children',
                                      repositoryId: @repository.id,
                                      objectId: @folder.cmis_object_id,
                                      maxItems: @max_items,
                                      skipCount: @skip_count,
                                      orderBy: @order_by })

      results = result['objects'].map do |r|
        ObjectFactory.create(r['object'], @repository)
      end

      QueryResult.new(results, result['numItems'], result['hasMoreItems'])
    end
<commit_msg>Adapted children to same implementations as query.<commit_after>module CMIS
  class Children

    # Options: from, page_size
    def initialize(folder, options = {})
      @folder = folder
      @options = options.stringify_keys!

      init_options
    end

    # Options: limit
    def each_result(options = {}, &block)
      return enum_for(:each_result, options) unless block_given?

      init_options
      limit = parse_limit(options)
      counter = 0

      while has_next?
        results.each do |object|
          break unless counter < limit
          yield object
          counter = counter.next
        end
      end
    end

    # Options: limit
    def each_page(options = {}, &block)
      return enum_for(:each_page, options) unless block_given?

      init_options
      limit = parse_limit(options)
      counter = 0

      while has_next?
        break unless counter < limit
        yield r = results
        counter += r.size
      end
    end

    def results
      result = do_get_children

      @skip_count += result.results.size
      @has_next = result.has_more_items
      @total = result.num_items

      result.results
    end

    def has_next?
      @has_next
    end

    def total
      @total ||= do_get_children.num_items
    end

    private

    def init_options
      @max_items = @options['page_size'] || 10
      @skip_count = @options['from'] || 0
      @order_by = @options['order_by']
      @has_next = true
    end

    def parse_limit(options)
      options.stringify_keys!
      limit = options['limit'] || 10
      limit = BigDecimal::INFINITY if limit == :all
      raise 'Not a valid limit' unless limit.is_a? Numeric
      limit
    end

    def do_get_children
      result = @folder.connection.execute!({ cmisselector: 'children',
                                             repositoryId: @folder.repository.id,
                                             objectId: @folder.cmis_object_id,
                                             maxItems: @max_items,
                                             skipCount: @skip_count,
                                             orderBy: @order_by })

      results = result['objects'].map do |r|
        ObjectFactory.create(r['object'], @folder.repository)
      end

      QueryResult.new(results, result['numItems'], result['hasMoreItems'])
    end

{'fraction_non_alphanumeric': 0.08593962469404406, 'fraction_numerical': 0.0027196083763937995, 'mean_word_length': 1.7758490566037737, 'pattern_counts': {'":': 0, '<': 5, '<?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': 15, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2444418', 'n_tokens_mistral': 1018, 'n_tokens_neox': 968, 'n_words': 238}