class MDQuery::DSL::DimensionSegmentDSL

DSL for describing a DimensionSegment

Public Class Methods

new(key,&proc) click to toggle source
# File lib/mdquery/dsl.rb, line 61
def initialize(key,&proc)
  @key = key
  @measure_modifiers = {}
  self.instance_eval(&proc)
end

Public Instance Methods

cast(c) click to toggle source

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_dimension(q) click to toggle source

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_dimension(v) click to toggle source

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
label(&proc) click to toggle source

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
modify(measure, &proc) click to toggle source

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(&proc) click to toggle source

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
values(&proc) click to toggle source

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

build(dimension) click to toggle source
# 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