Class: MDQuery::Model::DimensionModel

Inherits:
Object
  • Object
show all
Defined in:
lib/mdquery/model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ DimensionModel

Returns a new instance of DimensionModel.



117
118
119
120
# File 'lib/mdquery/model.rb', line 117

def initialize(attrs)
  MDQuery::Util.assign_attributes(self, attrs, [:key, :label, :segment_models])
  # validate # don't call validate, it's called by the DSL builder
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



113
114
115
# File 'lib/mdquery/model.rb', line 113

def key
  @key
end

#labelObject (readonly)

Returns the value of attribute label.



114
115
116
# File 'lib/mdquery/model.rb', line 114

def label
  @label
end

#segment_modelsObject (readonly)

Returns the value of attribute segment_models.



115
116
117
# File 'lib/mdquery/model.rb', line 115

def segment_models
  @segment_models
end

Instance Method Details

#index_list(prefixes = nil) ⇒ Object

for each prefix emit one item for the index of each segment_model. e.g. if we have 2 segment_models and are give prefixes [[0],] then the result is [[0,0],,[1,0],]. used in the calculation of the cross-join of segment indexes across all dimensions



135
136
137
# File 'lib/mdquery/model.rb', line 135

def index_list(prefixes=nil)
  (0...segment_models.length).reduce([]){|l, i| l + (prefixes||[[]]).map{|prefix| prefix.clone << i}}
end

#inspectObject



127
128
129
# File 'lib/mdquery/model.rb', line 127

def inspect
  "#<DimensionDefinition: key=#{key.inspect}, segment_models=#{segment_models.inspect}>"
end

#validateObject



122
123
124
125
# File 'lib/mdquery/model.rb', line 122

def validate
  raise "no key!" if !key
  raise "no segment_models!" if !segment_models || segment_models.empty?
end