class MDQuery::DSL::DatasetDSL
DSL
for defining a Dataset
with a number of Measures over a number of Dimensions where each Dimension consists of a number of Segments
Public Class Methods
new(&proc)
click to toggle source
# File lib/mdquery/dsl.rb, line 159 def initialize(&proc) raise "no block!" if !proc @dimensions=[] @measures=[] self.instance_eval(&proc) end
Public Instance Methods
dimension(key, &proc)
click to toggle source
define a Dimension
-
key
the key identifying the Dimension in theDataset
-
proc
aDimensionDSL
Proc
# File lib/mdquery/dsl.rb, line 145 def dimension(key, &proc) @dimensions << DimensionDSL.new(key, &proc) end
measure(key, definition, cast=nil)
click to toggle source
define a Measure
-
key
the key identifying the Measure in theDataset
-
definition
the SQL fragment defining the measure -
cast
a symbol identifying a case from MDQuery::Model::CASTS. Optional
# File lib/mdquery/dsl.rb, line 153 def measure(key, definition, cast=nil) @measures << MeasureDSL.new(key, definition, cast) end
source(scope)
click to toggle source
define the datasource for the Dataset
-
scope
an ActiveRecord scope, used as the basis for all region queries
# File lib/mdquery/dsl.rb, line 137 def source(scope) raise "source already set" if @source @source = scope end
Private Instance Methods
build()
click to toggle source
# File lib/mdquery/dsl.rb, line 166 def build ds = @dimensions.map{|d| d.send(:build)} ms = @measures.map{|m| m.send(:build)} MDQuery::Model::DatasetModel.new(:source=>@source, :dimension_models=>ds, :measure_models=>ms) end