Class: Chicago::Schema::ColumnParser

Inherits:
Object
  • Object
show all
Defined in:
lib/chicago/schema/column_parser.rb

Overview

Parses AST column representations, returning an Array of QueryColumns.

Columns can be simple dotted references, like

"sales.product.name"

calculations like:

{:column => "sales.total", :op => "sum"}

or pivoted calculations like:

{:column => "sales.total",
 :op => "sum"
 :pivot => "sales.date.year"}

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ ColumnParser

Creates a new ColumnParser for a schema.



24
25
26
# File 'lib/chicago/schema/column_parser.rb', line 24

def initialize(schema)
  @schema = schema
end

Instance Method Details

#parse(elem) ⇒ Array<Column>

Parses a column element. An element may be a string reference like “foo.bar”, or more complicated like => “foo.bar”, :op => “sum”

Returns:

  • (Array<Column>)

    an array of columns. In most cases this will be a 1-element array, unless the column is pivoted.



35
36
37
# File 'lib/chicago/schema/column_parser.rb', line 35

def parse(elem)
  [_parse(elem)].flatten
end