Class: Airrel::WhereClause

Inherits:
Object
  • Object
show all
Defined in:
lib/airrel/where_clause.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(predicates = []) ⇒ WhereClause

Returns a new instance of WhereClause.



7
8
9
# File 'lib/airrel/where_clause.rb', line 7

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

Instance Attribute Details

#predicatesObject (readonly)

Returns the value of attribute predicates.



5
6
7
# File 'lib/airrel/where_clause.rb', line 5

def predicates
  @predicates
end

Instance Method Details

#any?Boolean

Returns:

  • (Boolean)


26
# File 'lib/airrel/where_clause.rb', line 26

def any? = @predicates.any?

#inspectObject



35
# File 'lib/airrel/where_clause.rb', line 35

def inspect = @predicates.inspect

#merge(conditions) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/airrel/where_clause.rb', line 11

def merge(conditions)
  new_predicates = case conditions
                   when Hash
                     [FormulaBuilder.hash_to_formula(conditions)]
                   when String
                     [conditions]
                   when Array
                     conditions
                   else
                     [conditions.to_s]
                   end

  WhereClause.new(@predicates + new_predicates)
end

#to_airtable_formulaObject



28
29
30
31
32
33
# File 'lib/airrel/where_clause.rb', line 28

def to_airtable_formula
  return nil if @predicates.empty?
  return @predicates.first if @predicates.size == 1

  "AND(#{@predicates.join(", ")})"
end