Class: Cubicle::Query

Inherits:
Object
  • Object
show all
Includes:
Dsl
Defined in:
lib/cubicle/query.rb,
lib/cubicle/query/dsl.rb,
lib/cubicle/query/dsl/time_intelligence.rb

Defined Under Namespace

Modules: Dsl

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Dsl

#alias_member, #by, #define, #limit, #offset, #order_by, #select, #select_all, #transient!, #where

Methods included from Dsl::TimeIntelligence

#from, #last, #last_complete, #mtd, #next, #this, #time_dimension, #time_range, #until, #ytd

Constructor Details

#initialize(aggregation) ⇒ Query

Returns a new instance of Query.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/cubicle/query.rb', line 8

def initialize(aggregation)
  @aggregation = aggregation

  @dimensions = Cubicle::MemberList.new
  @measures = Cubicle::MemberList.new
  @source_collection_name = @aggregation.target_collection_name
  @where, @from_date, @to_date, @date_dimension, @time_period, @limit, @offset = nil
  @all_dimensions, @all_measures = false, false
  @transient = false
  @by=[]
  @order_by=[]
  @from_date_filter = "$gte"
  @to_date_filter = "$lte"
  @query_aliases=HashWithIndifferentAccess.new
  @named_expressions=HashWithIndifferentAccess.new
end

Instance Attribute Details

#aggregationObject (readonly)

Returns the value of attribute aggregation.



5
6
7
# File 'lib/cubicle/query.rb', line 5

def aggregation
  @aggregation
end

#named_expressionsObject (readonly)

Returns the value of attribute named_expressions.



5
6
7
# File 'lib/cubicle/query.rb', line 5

def named_expressions
  @named_expressions
end

#query_aliasesObject (readonly)

Returns the value of attribute query_aliases.



5
6
7
# File 'lib/cubicle/query.rb', line 5

def query_aliases
  @query_aliases
end

#source_collection_nameObject

Returns the value of attribute source_collection_name.



6
7
8
# File 'lib/cubicle/query.rb', line 6

def source_collection_name
  @source_collection_name
end

#time_periodObject (readonly)

Returns the value of attribute time_period.



5
6
7
# File 'lib/cubicle/query.rb', line 5

def time_period
  @time_period
end

#transientObject (readonly)

Returns the value of attribute transient.



5
6
7
# File 'lib/cubicle/query.rb', line 5

def transient
  @transient
end

Instance Method Details

#all_dimensions?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/cubicle/query.rb', line 45

def all_dimensions?
  @all_dimensions
end

#all_measures?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/cubicle/query.rb', line 41

def all_measures?
  @all_measures
end

#cloneObject



25
26
27
# File 'lib/cubicle/query.rb', line 25

def clone
  Marshal.load(Marshal.dump(self))
end

#dimension_namesObject



49
50
51
# File 'lib/cubicle/query.rb', line 49

def dimension_names
  return dimensions.map{|dim|dim.name.to_s}
end

#dimensionsObject



57
58
59
60
# File 'lib/cubicle/query.rb', line 57

def dimensions
  return @dimensions unless all_dimensions?
  @aggregation.dimensions.collect{|dim|convert_dimension(dim)}
end

#execute(options = {}) ⇒ Object



67
68
69
# File 'lib/cubicle/query.rb', line 67

def execute(options={})
  @aggregation.execute_query(self,options)
end

#measuresObject



62
63
64
65
# File 'lib/cubicle/query.rb', line 62

def measures
  return @measures unless all_measures?
  @aggregation.measures.collect{|measure|convert_measure(measure)}
end

#member_namesObject



53
54
55
# File 'lib/cubicle/query.rb', line 53

def member_names
  return (dimensions + measures).map{|m|m.name.to_s}
end

#selected?(member = nil) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
# File 'lib/cubicle/query.rb', line 29

def selected?(member = nil)
  return (@dimensions.length > 0 || @measures.length > 0) unless member
  member_name = member.kind_of?(Cubicle::Member) ? member.name : unalias(member.to_s)
  return @dimensions[member_name] ||
          @measures[member_name]
end

#transient?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/cubicle/query.rb', line 36

def transient?
  @transient || @aggregation.transient?
end