Class: QueryHelper::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/query_helper/filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operator_code:, criterion:, comparate:, aggregate: false, qualify_clause: false) ⇒ Filter

Returns a new instance of Filter.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/query_helper/filter.rb', line 8

def initialize(
  operator_code:,
  criterion:,
  comparate:,
  aggregate: false,
  qualify_clause: false
)
  @operator_code = operator_code
  @criterion = criterion # Converts to a string to be inserted into sql.
  @comparate = comparate
  @aggregate = aggregate
  @qualify_clause = qualify_clause
  @bind_variable = ('a'..'z').to_a.shuffle[0,20].join.to_sym

  translate_operator_code()
  mofify_criterion()
  modify_comparate()
  validate_criterion()
end

Instance Attribute Details

#aggregateObject

Returns the value of attribute aggregate.



6
7
8
# File 'lib/query_helper/filter.rb', line 6

def aggregate
  @aggregate
end

#bind_variableObject

Returns the value of attribute bind_variable.



6
7
8
# File 'lib/query_helper/filter.rb', line 6

def bind_variable
  @bind_variable
end

#comparateObject

Returns the value of attribute comparate.



6
7
8
# File 'lib/query_helper/filter.rb', line 6

def comparate
  @comparate
end

#criterionObject

Returns the value of attribute criterion.



6
7
8
# File 'lib/query_helper/filter.rb', line 6

def criterion
  @criterion
end

#operatorObject

Returns the value of attribute operator.



6
7
8
# File 'lib/query_helper/filter.rb', line 6

def operator
  @operator
end

#operator_codeObject

Returns the value of attribute operator_code.



6
7
8
# File 'lib/query_helper/filter.rb', line 6

def operator_code
  @operator_code
end

#qualify_clauseObject

Returns the value of attribute qualify_clause.



6
7
8
# File 'lib/query_helper/filter.rb', line 6

def qualify_clause
  @qualify_clause
end

Instance Method Details

#sql_stringObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/query_helper/filter.rb', line 28

def sql_string
  case operator_code
  when "in", "notin"
    "#{comparate} #{operator} (:#{bind_variable})"
  when "null"
    "#{comparate} #{operator}"
  else
    "#{comparate} #{operator} :#{bind_variable}"
  end

end