Class: ActiveWarehouse::CubeQueryResult
- Inherits:
-
Object
- Object
- ActiveWarehouse::CubeQueryResult
- Defined in:
- lib/active_warehouse/cube_query_result.rb
Overview
Class that holds the results of a Cube query
Instance Attribute Summary collapse
-
#aggregate_fields_hash ⇒ Object
readonly
Returns the value of attribute aggregate_fields_hash.
Instance Method Summary collapse
-
#add_data(row_value, col_value, aggregated_facts) ⇒ Object
Add a hash of aggregated facts for the given row and column values.
-
#each ⇒ Object
iterate through every row and column combination.
-
#has_row_values?(row_value) ⇒ Boolean
Return true if the aggregate map includes the specified row value.
-
#initialize(aggregate_fields) ⇒ CubeQueryResult
constructor
Initialize the aggregate map with an array of AggregateField instances.
- #value(row_value, col_value, field_label) ⇒ Object
-
#values(row_value, col_value) ⇒ Object
returns a hash of type casted fact values for the intersection of row_value and col_value.
Constructor Details
#initialize(aggregate_fields) ⇒ CubeQueryResult
Initialize the aggregate map with an array of AggregateField instances. The AggregateFields are used to typecast the raw values coming from the database. Thank you very little, DBI.
9 10 11 12 13 14 |
# File 'lib/active_warehouse/cube_query_result.rb', line 9 def initialize(aggregate_fields) raise ArgumentError, "aggregate_fields must not be empty" unless aggregate_fields && aggregate_fields.size > 0 @aggregate_fields_hash = {} aggregate_fields.each {|c| @aggregate_fields_hash[c.label] = c} @values_map = {} end |
Instance Attribute Details
#aggregate_fields_hash ⇒ Object (readonly)
Returns the value of attribute aggregate_fields_hash.
4 5 6 |
# File 'lib/active_warehouse/cube_query_result.rb', line 4 def aggregate_fields_hash @aggregate_fields_hash end |
Instance Method Details
#add_data(row_value, col_value, aggregated_facts) ⇒ Object
Add a hash of aggregated facts for the given row and column values. For instance, add_data(‘Southeast’, 2005, => 40000, :sales_count => 40) This method will typecast the values in aggregated_facts.
46 47 48 49 50 |
# File 'lib/active_warehouse/cube_query_result.rb', line 46 def add_data(row_value, col_value, aggregated_facts) #puts "Adding data for #{row_value}, #{col_value} [data=[#{aggregated_facts.join(',')}]]" @values_map[row_value] ||= {} @values_map[row_value][col_value] = typecast_facts(aggregated_facts) end |
#each ⇒ Object
iterate through every row and column combination
22 23 24 25 26 |
# File 'lib/active_warehouse/cube_query_result.rb', line 22 def each @values_map.each do |key, value| yield key, value end end |
#has_row_values?(row_value) ⇒ Boolean
Return true if the aggregate map includes the specified row value
17 18 19 |
# File 'lib/active_warehouse/cube_query_result.rb', line 17 def has_row_values?(row_value) @values_map.has_key?(row_value) end |
#value(row_value, col_value, field_label) ⇒ Object
28 29 30 31 |
# File 'lib/active_warehouse/cube_query_result.rb', line 28 def value(row_value, col_value, field_label) #puts "getting value #{row_value},#{col_value},#{field_label}" values(row_value, col_value)[field_label] end |
#values(row_value, col_value) ⇒ Object
returns a hash of type casted fact values for the intersection of row_value and col_value
35 36 37 38 39 40 41 |
# File 'lib/active_warehouse/cube_query_result.rb', line 35 def values(row_value, col_value) row = @values_map[row_value] return empty_hash_for_missing_row_or_column if row.nil? facts = row[col_value] return empty_hash_for_missing_row_or_column if facts.nil? facts end |