Class: Cubicle::Data::Table

Inherits:
Array
  • Object
show all
Defined in:
lib/cubicle/data/table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query, query_results, total_count = nil) ⇒ Table

Returns a new instance of Table.



6
7
8
9
10
11
12
13
14
# File 'lib/cubicle/data/table.rb', line 6

def initialize(query,query_results,total_count = nil)
  @dimensions = Marshal.load(Marshal.dump(query.dimensions))
  @measures   = Marshal.load(Marshal.dump(query.measures))
  @time_dimension_name = query.time_dimension.name if query.respond_to?(:time_dimension) && query.time_dimension
  @time_period = query.time_period if query.respond_to?(:time_period)
  @time_range = query.time_range if query.respond_to?(:time_range)
  extract_data(query,query_results)
  @total_count = total_count if total_count
end

Instance Attribute Details

#dimensionsObject (readonly)

Returns the value of attribute dimensions.



4
5
6
# File 'lib/cubicle/data/table.rb', line 4

def dimensions
  @dimensions
end

#measuresObject (readonly)

Returns the value of attribute measures.



4
5
6
# File 'lib/cubicle/data/table.rb', line 4

def measures
  @measures
end

#time_dimension_nameObject (readonly)

Returns the value of attribute time_dimension_name.



4
5
6
# File 'lib/cubicle/data/table.rb', line 4

def time_dimension_name
  @time_dimension_name
end

#time_periodObject (readonly)

Returns the value of attribute time_period.



4
5
6
# File 'lib/cubicle/data/table.rb', line 4

def time_period
  @time_period
end

#time_rangeObject (readonly)

Returns the value of attribute time_range.



4
5
6
# File 'lib/cubicle/data/table.rb', line 4

def time_range
  @time_range
end

#total_countObject (readonly)

Returns the value of attribute total_count.



4
5
6
# File 'lib/cubicle/data/table.rb', line 4

def total_count
  @total_count
end

Instance Method Details

#dimension_namesObject



16
17
18
# File 'lib/cubicle/data/table.rb', line 16

def dimension_names
  @dimensions.map{|d|d.name}
end

#hierarchize(*args) ⇒ Object Also known as: hierarchize_by, by



24
25
26
# File 'lib/cubicle/data/table.rb', line 24

def hierarchize(*args)
  Cubicle::Data::Hierarchy.hierarchize_table(self,args)
end

#measure_namesObject



20
21
22
# File 'lib/cubicle/data/table.rb', line 20

def measure_names
  @measures.map{|m|m.name}
end

#records_per_page=(records_per_page) ⇒ Object



30
31
32
# File 'lib/cubicle/data/table.rb', line 30

def records_per_page=(records_per_page)
  @records_per_page=records_per_page
end

#total_pagesObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/cubicle/data/table.rb', line 34

def total_pages
  if (!defined?(@total_count))
    raise "Cannot find the total number of pages without setting the total count"
  end

  if (!defined?(@records_per_page))
    raise "Cannot find the total number of pages without setting the number of records per page"
  end

  (@total_count.to_f / @records_per_page.to_f).ceil
end