<commit_before>module RBattlenet
  module Endpoints
    class Base
      SUPPORTED_FIELDS = [:itself]

      def self.all
        raise RBattlenet::Errors::IndexNotSupported.new unless defined?(index_path)
        RBattlenet.get [[[[:itself, index_path]], :index]] do
          yield if block_given?
        end
      end

      def self.find(subjects, fields: [:itself])
        raise RBattlenet::Errors::FindNotSupported.new unless defined?(path)

        if !fields.is_a? Array || (fields.map(&:to_sym) - SUPPORTED_FIELDS).any?
          raise RBattlenet::Errors::InvalidFieldsOption.new
        end

        payload = [subjects].flatten.map do |subject|
          subject_fields = [:itself] + fields + (subject[:fields] if subject.is_a?(Hash)).to_a
          [subject_fields.uniq.map{ |field| [field, send(field).path(subject)] }, subject]
        end

        RBattlenet.get payload do
          yield if block_given?
        end
      end
    end
  end
end<commit_msg>Make blocks work.<commit_after>module RBattlenet
  module Endpoints
    class Base
      SUPPORTED_FIELDS = [:itself]

      def self.all
        raise RBattlenet::Errors::IndexNotSupported.new unless defined?(index_path)
        RBattlenet.get [[[[:itself, index_path]], :index]] do |subject, data|
          yield if block_given?
        end
      end

      def self.find(subjects, fields: [:itself])
        raise RBattlenet::Errors::FindNotSupported.new unless defined?(path)

        if !fields.is_a? Array || (fields.map(&:to_sym) - SUPPORTED_FIELDS).any?
          raise RBattlenet::Errors::InvalidFieldsOption.new
        end

        payload = [subjects].flatten.map do |subject|
          subject_fields = [:itself] + fields + (subject[:fields] if subject.is_a?(Hash)).to_a
          [subject_fields.uniq.map{ |field| [field, send(field).path(subject)] }, subject]
        end

        RBattlenet.get payload do |subject, data|
          yield if block_given?
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.1123991935483871, 'fraction_numerical': 0.0, 'mean_word_length': 2.6355311355311355, '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': '4114660', 'n_tokens_mistral': 643, 'n_tokens_neox': 616, 'n_words': 139}