class MDQuery::DSL::DimensionSegmentDSL
DSL
for describing a DimensionSegment
Public Class Methods
# File lib/mdquery/dsl.rb, line 61 def initialize(key,&proc) @key = key @measure_modifiers = {} self.instance_eval(&proc) end
Public Instance Methods
define a cast to convert values into the desired datatype
-
c
a keyword key for the casts in MDQuery::Model::Casts
# File lib/mdquery/dsl.rb, line 46 def cast(c) raise "unknown cast: #{c.inspect}" if !MDQuery::Model::CASTS.keys.include?(c) @value_cast = c end
extract DimensionValues from data for this segment. exclusive of fix_dimension
-
q
SQL select string fragment for the dimension value
# File lib/mdquery/dsl.rb, line 17 def extract_dimension(q) @extract_dimension_query=q end
fix the Dimension value for this segment. exclusive of extract_dimension
-
v
the Dimension value for this segment
# File lib/mdquery/dsl.rb, line 11 def fix_dimension(v) @fixed_dimension_value=v end
set a Proc to be used to convert Dimension values into labels. Optional
-
proc
a Proc of a single parameter which will be called to convert Dimension values
into labels
# File lib/mdquery/dsl.rb, line 39 def label(&proc) raise "no block!" if !proc @label_proc = proc end
set a Proc to be used to modify the measure-value in any query using this segment
-
measure
a keyword describing the Measure -
proc
a Proc of a single parameter which will be used to transform the measure value
# File lib/mdquery/dsl.rb, line 54 def modify(measure, &proc) raise "no block!" if !proc @measure_modifiers[measure] = proc end
Narrow the datasource to extract this segment. Optional
-
proc
a Proc of a single parameter, an ActiveRecord Scope to be narrowed
# File lib/mdquery/dsl.rb, line 23 def narrow(&proc) raise "no block!" if !proc @narrow_proc = proc end
Define an ordered list of all possible Dimension Values for the segment. Optional
-
proc
a Proc of a single parameter, an ActiveRecord Scope which can be used
to query for the values
# File lib/mdquery/dsl.rb, line 31 def values(&proc) raise "no block!" if !proc @values_proc = proc end
Private Instance Methods
# File lib/mdquery/dsl.rb, line 67 def build(dimension) MDQuery::Model::DimensionSegmentModel.new(:dimension_model=>dimension, :key=>@key, :fixed_dimension_value=>@fixed_dimension_value, :extract_dimension_query=>@extract_dimension_query, :narrow_proc=>@narrow_proc, :values_proc=>@values_proc, :label_proc=>@label_proc, :value_cast=>@value_cast, :measure_modifiers=>@measure_modifiers) end