<commit_before>require 'forwardable'

module Gimlet
  module Queryable
    module API
      extend Forwardable

      def select(options = {})
        selecting = @instances
        options[:where].each do |attribute, operator, argument|
          selecting = selecting.select do |id, instance|
            instance[attribute].send(operator, argument)
          end
        end
        selecting.values
      end

      def new_query
        current_scope || Query.new(self)
      end

      def_delegators :new_query, :all, :where, :first, :last, :count
    end

    class Query
      include Enumerable
      extend Forwardable

      def initialize(model)
        @model = model
        @where = []
      end

      def where(hash)
        hash.each do |attribute, value|
          case value
          when Array
            @where.push([attribute, :in?, value])
          when Regexp
            @where.push([attribute, :=~, value])
          else
            @where.push([attribute, :==, value])
          end
        end
        self
      end

      def all<commit_msg>Add a comment for specification<commit_after>require 'forwardable'

module Gimlet
  module Queryable
    module API
      extend Forwardable

      def select(options = {})
        selecting = @instances
        options[:where].each do |attribute, operator, argument|
          selecting = selecting.select do |id, instance|
            instance[attribute].send(operator, argument)
          end
        end
        selecting.values
      end

      def new_query
        current_scope || Query.new(self)
      end

      def_delegators :new_query, :all, :where, :first, :last, :count
    end

    class Query
      include Enumerable
      extend Forwardable

      def initialize(model)
        @model = model
        @where = []
      end

      def where(hash)
        hash.each do |attribute, value|
          case value
          when Array
            @where.push([attribute, :in?, value]) # should be :== ?
          when Regexp
            @where.push([attribute, :=~, value])
          else
            @where.push([attribute, :==, value])
          end
        end
        self
      end

      def all
{'fraction_non_alphanumeric': 0.08812785388127854, 'fraction_numerical': 0.0, 'mean_word_length': 1.7251243781094527, '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': '4502052', 'n_tokens_mistral': 592, 'n_tokens_neox': 578, 'n_words': 167}