Class: Spout::Models::Tables::NumericVsChoices

Inherits:
Default
  • Object
show all
Defined in:
lib/spout/models/tables/numeric_vs_choices.rb

Instance Attribute Summary

Attributes inherited from Default

#chart_variable, #subjects, #subtitle, #totals, #variable

Instance Method Summary collapse

Methods inherited from Default

#initialize, #to_hash, #valid?

Constructor Details

This class inherits a constructor from Spout::Models::Tables::Default

Instance Method Details

#footersObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/spout/models/tables/numeric_vs_choices.rb', line 18

def footers
  return [] unless @totals
  total_values = Spout::Helpers::ArrayStatistics.calculations.collect do |_calculation_label, calculation_method, calculation_type, calculation_format|
    total_count = @filtered_subjects.collect(&@variable.id.to_sym).send(calculation_method)
    { text: Spout::Helpers::TableFormatting.format_number(total_count, calculation_type, calculation_format), style: "font-weight:bold" }
  end

  [
    [{ text: "Total", style: "font-weight:bold" }] + total_values + [{ text: Spout::Helpers::TableFormatting.format_number(@filtered_subjects.count, :count), style: "font-weight:bold" }]
  ]
end

#headersObject



14
15
16
# File 'lib/spout/models/tables/numeric_vs_choices.rb', line 14

def headers
  [[""] + Spout::Helpers::ArrayStatistics.calculations.collect(&:first) + ["Total"]]
end

#rowsObject



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/spout/models/tables/numeric_vs_choices.rb', line 30

def rows
  filtered_domain_options(@chart_variable).collect do |option|
    row_subjects = @filtered_subjects.select { |s| s.send(@chart_variable.id) == option.value }

    row_cells = Spout::Helpers::ArrayStatistics.calculations.collect do |_calculation_label, calculation_method, calculation_type, calculation_format|
      count = row_subjects.collect(&@variable.id.to_sym).send(calculation_method)
      (count == 0 && calculation_method == :count) ? { text: "-", class: "text-muted" } : Spout::Helpers::TableFormatting.format_number(count, calculation_type, calculation_format)
    end

    [option.display_name] + row_cells + [{ text: Spout::Helpers::TableFormatting.format_number(row_subjects.count, :count), style: "font-weight:bold" }]
  end
end

#titleObject



10
11
12
# File 'lib/spout/models/tables/numeric_vs_choices.rb', line 10

def title
  "#{@chart_variable.display_name} vs #{@variable.display_name}"
end