Class: Cubicle::Data

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Data.



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

def initialize(query,query_results,total_count = nil)
  @dimension_names = query.dimensions.map{|d|d.name}
  @measure_names = query.measures.map{|m|m.name}
  @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_results)
  @total_count = total_count if total_count
end

Instance Attribute Details

#dimension_namesObject (readonly)

Returns the value of attribute dimension_names.



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

def dimension_names
  @dimension_names
end

#measure_namesObject (readonly)

Returns the value of attribute measure_names.



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

def measure_names
  @measure_names
end

#total_countObject (readonly)

Returns the value of attribute total_count.



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

def total_count
  @total_count
end

Instance Method Details

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



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

def hierarchize(*args)
  args = [@time_dimension_name || @dimension_names].flatten if args.blank?
  extract_dimensions args, self
end

#records_per_page=(records_per_page) ⇒ Object



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

def records_per_page=(records_per_page)
  @records_per_page=records_per_page
end

#total_pagesObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/cubicle/data.rb', line 27

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