Class: ActiveWarehouse::AggregateMap
- Inherits:
-
Object
- Object
- ActiveWarehouse::AggregateMap
- Defined in:
- lib/active_warehouse/cube.rb
Overview
In-memory map of aggregate values
Instance Attribute Summary collapse
-
#length ⇒ Object
readonly
Returns the value of attribute length.
Instance Method Summary collapse
-
#add_data(row_path, col_path, data_array) ⇒ Object
Add an array of data for the given row and column path.
-
#has_row_path?(row_path) ⇒ Boolean
Return true if the aggregate map includes the specified row path.
-
#initialize ⇒ AggregateMap
constructor
Initialize the aggregate map.
-
#value(row_path, col_path, field_index) ⇒ Object
Get the value for the specified row path, column path and field index.
-
#values(row_path, col_path) ⇒ Object
Get an array of the values for the specified row path and column path.
Constructor Details
#initialize ⇒ AggregateMap
Initialize the aggregate map
267 268 269 |
# File 'lib/active_warehouse/cube.rb', line 267 def initialize @m = {} end |
Instance Attribute Details
#length ⇒ Object (readonly)
Returns the value of attribute length.
264 265 266 |
# File 'lib/active_warehouse/cube.rb', line 264 def length @length end |
Instance Method Details
#add_data(row_path, col_path, data_array) ⇒ Object
Add an array of data for the given row and column path
296 297 298 299 300 301 |
# File 'lib/active_warehouse/cube.rb', line 296 def add_data(row_path, col_path, data_array) @length ||= data_array.length #puts "Adding data for #{row_path}, #{col_path} [data=[#{data_array.join(',')}]]" @m[row_path] ||= {} @m[row_path][col_path] = data_array end |
#has_row_path?(row_path) ⇒ Boolean
Return true if the aggregate map includes the specified row path
272 273 274 |
# File 'lib/active_warehouse/cube.rb', line 272 def has_row_path?(row_path) @m.has_key?(row_path) end |
#value(row_path, col_path, field_index) ⇒ Object
Get the value for the specified row path, column path and field index
277 278 279 280 281 282 283 284 |
# File 'lib/active_warehouse/cube.rb', line 277 def value(row_path, col_path, field_index) #puts "Getting value for #{row_path}, #{col_path} [field=#{field_index}]" row = @m[row_path] return 0 if row.nil? col = row[col_path] return 0 if col.nil? return col[field_index] || 0 end |
#values(row_path, col_path) ⇒ Object
Get an array of the values for the specified row path and column path
287 288 289 290 291 292 293 |
# File 'lib/active_warehouse/cube.rb', line 287 def values(row_path, col_path) row = @m[row_path] return Array.new(length, 0) if row.nil? col = row[col_path] return Array.new(length, 0) if col.nil? col end |