Class: ActiveReporter::Serializer::NestedHashWithId

Inherits:
Base
  • Object
show all
Defined in:
lib/active_reporter/serializer/nested_hash_with_id.rb

Constant Summary collapse

ID_DELIMITER =
"✦".freeze

Instance Attribute Summary

Attributes inherited from Base

#report

Instance Method Summary collapse

Methods inherited from Base

#axis_summary, #filter_summary, #human_aggregator_label, #human_aggregator_value_label, #human_category_value_label, #human_dimension_label, #human_dimension_value_label, #human_null_value_label, #human_number_value_label, #human_time_value_label, #initialize, #record_type, #time_formats

Constructor Details

This class inherits a constructor from ActiveReporter::Serializer::Base

Instance Method Details

#tableObject



6
7
8
9
10
11
12
13
# File 'lib/active_reporter/serializer/nested_hash_with_id.rb', line 6

def table
  report.hashed_data.collect { |row| row.map { |k,v| [k, (v.respond_to?(:min) ? v.min : v).to_s] }.to_h }.collect do |row|
    row_with_id = row.merge(_id: row.slice(*report.grouper_names).values.join(key_delimiter))
    report.grouper_names.reverse.inject(row_with_id.slice(*report.all_aggregators.keys.prepend(:_id))) do |nested_row_data, group|
      { row_with_id[group] => nested_row_data }
    end
  end.reduce({}, :deep_merge)
end