Class: Redis::Commands::Search::PredicateCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/redis/commands/modules/search/query.rb

Overview

An ordered collection of predicates joined with AND (a space) or OR (+ | +).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ PredicateCollection

Returns a new instance of PredicateCollection.

Parameters:

  • type (Symbol)

    :and to join with a space, :or to join with |



717
718
719
720
# File 'lib/redis/commands/modules/search/query.rb', line 717

def initialize(type)
  @type = type
  @predicates = []
end

Instance Attribute Details

#predicatesSymbol, Array<Predicate, PredicateCollection> (readonly)

Returns:



714
715
716
# File 'lib/redis/commands/modules/search/query.rb', line 714

def predicates
  @predicates
end

#typeSymbol, Array<Predicate, PredicateCollection> (readonly)

Returns:



714
715
716
# File 'lib/redis/commands/modules/search/query.rb', line 714

def type
  @type
end

Instance Method Details

#add(predicate) ⇒ Array

Add a predicate (or nested collection) to this collection.

Parameters:

Returns:

  • (Array)

    the updated list of predicates



726
727
728
# File 'lib/redis/commands/modules/search/query.rb', line 726

def add(predicate)
  @predicates << predicate
end

#to_sString

Returns the parenthesised, joined query-string fragment.

Returns:

  • (String)

    the parenthesised, joined query-string fragment



731
732
733
734
# File 'lib/redis/commands/modules/search/query.rb', line 731

def to_s
  joiner = @type == :or ? ' | ' : ' '
  "(#{@predicates.join(joiner)})"
end