Class: Rgviz::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/rgviz/nodes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#formatsObject

Returns the value of attribute formats.



11
12
13
# File 'lib/rgviz/nodes.rb', line 11

def formats
  @formats
end

#group_byObject

Returns the value of attribute group_by.



5
6
7
# File 'lib/rgviz/nodes.rb', line 5

def group_by
  @group_by
end

#labelsObject

Returns the value of attribute labels.



10
11
12
# File 'lib/rgviz/nodes.rb', line 10

def labels
  @labels
end

#limitObject

Returns the value of attribute limit.



8
9
10
# File 'lib/rgviz/nodes.rb', line 8

def limit
  @limit
end

#offsetObject

Returns the value of attribute offset.



9
10
11
# File 'lib/rgviz/nodes.rb', line 9

def offset
  @offset
end

#optionsObject

Returns the value of attribute options.



12
13
14
# File 'lib/rgviz/nodes.rb', line 12

def options
  @options
end

#order_byObject

Returns the value of attribute order_by.



7
8
9
# File 'lib/rgviz/nodes.rb', line 7

def order_by
  @order_by
end

#pivotObject

Returns the value of attribute pivot.



6
7
8
# File 'lib/rgviz/nodes.rb', line 6

def pivot
  @pivot
end

#selectObject

Returns the value of attribute select.



3
4
5
# File 'lib/rgviz/nodes.rb', line 3

def select
  @select
end

#whereObject

Returns the value of attribute where.



4
5
6
# File 'lib/rgviz/nodes.rb', line 4

def where
  @where
end

Instance Method Details

#accept(visitor) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rgviz/nodes.rb', line 18

def accept(visitor)
  if visitor.visit_query self
    select.accept visitor if select
    where.accept visitor if where
    group_by.accept visitor if group_by
    pivot.accept visitor if pivot
    order_by.accept visitor if order_by
    labels.each{|x| x.accept visitor} if labels
    formats.each{|x| x.accept visitor} if formats
  end
  visitor.end_visit_query self
end

#select?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/rgviz/nodes.rb', line 14

def select?
  @select && @select.columns && @select.columns.length > 0
end

#to_sObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rgviz/nodes.rb', line 31

def to_s
  str = ''
  if select
    if select.columns.empty?
      str << "select * "
    else
      str << "select #{select.to_s} "
    end
  end
  str << "where #{where} " if where
  str << "group by #{group_by} " if group_by
  str << "pivot #{pivot} " if pivot
  str << "order by #{order_by} " if order_by
  str << "limit #{limit} " if limit
  str << "offset #{offset} " if offset
  str << "label #{labels.map(&:to_s).join(', ')} " if labels
  str << "format #{formats.map(&:to_s).join(', ')} " if formats
  str << "options #{options} " if options
  str.strip
end