Class: Nexter::Query::Section

Inherits:
Object
  • Object
show all
Defined in:
lib/nexter/query/section.rb

Overview

Iterates over the columns, extracts their values and builds query part that says :

> “col1 = value1” > “col2 = value2”

then joins them with AND :

> “col1 = value1 AND col2 = value2”

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(columns) ⇒ Section

TODO : check if compass is needed (don’t think so!)



17
18
19
20
# File 'lib/nexter/query/section.rb', line 17

def initialize(columns)
  @columns = columns
  @compass = compass
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



14
15
16
# File 'lib/nexter/query/section.rb', line 14

def columns
  @columns
end

#compassObject (readonly)

Returns the value of attribute compass.



14
15
16
# File 'lib/nexter/query/section.rb', line 14

def compass
  @compass
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/nexter/query/section.rb', line 33

def blank?
  iterate.blank?
end

#iterateObject Also known as: sql



22
23
24
25
26
27
28
29
30
# File 'lib/nexter/query/section.rb', line 22

def iterate
  @where ||= columns.map do |column|
    if column[:val]
      "#{column[:col]} = #{quote(column[:val])}"
    else
      "#{column[:col]} IS NULL"
    end
  end.join(' AND ')
end