Class: JsonQL::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/json_q_l/executor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dataset) ⇒ Executor

Returns a new instance of Executor.



3
4
5
# File 'lib/json_q_l/executor.rb', line 3

def initialize(dataset)
  @dataset = dataset
end

Instance Attribute Details

#datasetObject (readonly)

Returns the value of attribute dataset.



35
36
37
# File 'lib/json_q_l/executor.rb', line 35

def dataset
  @dataset
end

#parserObject (readonly)

Returns the value of attribute parser.



35
36
37
# File 'lib/json_q_l/executor.rb', line 35

def parser
  @parser
end

Instance Method Details

#execute(query) ⇒ Object



7
8
9
10
11
# File 'lib/json_q_l/executor.rb', line 7

def execute(query)
  @parser = Parser.new(query)

  selected_columns
end

#filtered_tableObject



21
22
23
24
25
26
27
28
29
# File 'lib/json_q_l/executor.rb', line 21

def filtered_table
  if parser.where_index
    tables.map do |table|
      table if parser.filter_conditions_from_tokens.call(table)
    end.compact
  else
    tables
  end
end

#selected_columnsObject



13
14
15
16
17
18
19
# File 'lib/json_q_l/executor.rb', line 13

def selected_columns
  if filtered_table.empty?
    "Nothing matched query"
  else
    parser.column_select.call(filtered_table)
  end
end

#tablesObject



31
32
33
# File 'lib/json_q_l/executor.rb', line 31

def tables
  parser.table_select.call(dataset)
end