Class: ParadeDB::Proximity::Clause
- Inherits:
-
Object
- Object
- ParadeDB::Proximity::Clause
- Includes:
- Chainable
- Defined in:
- lib/parade_db/proximity.rb
Instance Attribute Summary collapse
-
#clauses ⇒ Object
readonly
Returns the value of attribute clauses.
-
#operand ⇒ Object
readonly
Returns the value of attribute operand.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*terms, operand: nil, clauses: []) ⇒ Clause
constructor
A new instance of Clause.
- #within(distance, *terms, ordered: false) ⇒ Object
Constructor Details
#initialize(*terms, operand: nil, clauses: []) ⇒ Clause
Returns a new instance of Clause.
42 43 44 45 |
# File 'lib/parade_db/proximity.rb', line 42 def initialize(*terms, operand: nil, clauses: []) @operand = operand || self.class.normalize_operand(terms) @clauses = clauses end |
Instance Attribute Details
#clauses ⇒ Object (readonly)
Returns the value of attribute clauses.
40 41 42 |
# File 'lib/parade_db/proximity.rb', line 40 def clauses @clauses end |
#operand ⇒ Object (readonly)
Returns the value of attribute operand.
40 41 42 |
# File 'lib/parade_db/proximity.rb', line 40 def operand @operand end |
Class Method Details
.normalize_operand(terms) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/parade_db/proximity.rb', line 63 def self.normalize_operand(terms) values = Array(terms).flatten(1).compact raise ArgumentError, "proximity requires at least one term" if values.empty? values.length == 1 ? values.first : values end |
Instance Method Details
#within(distance, *terms, ordered: false) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/parade_db/proximity.rb', line 47 def within(distance, *terms, ordered: false) normalized_operand = begin self.class.normalize_operand(terms) rescue ArgumentError => e raise unless e. == "proximity requires at least one term" raise ArgumentError, "within requires at least one term" end self.class.new( operand: operand, clauses: clauses + [Within.new(distance, normalized_operand, ordered: ordered)] ) end |