Class: Spout::Models::Tables::ChoicesVsNumeric
- Defined in:
- lib/spout/models/tables/choices_vs_numeric.rb
Overview
Generates a table that displays choices versus numeric values
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
#footers ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/spout/models/tables/choices_vs_numeric.rb', line 24 def total_values = [:quartile_one, :quartile_two, :quartile_three, :quartile_four].collect do |quartile| { text: Spout::Helpers::TableFormatting.format_number(@filtered_subjects.send(quartile).count, :count), 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 |
#headers ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/spout/models/tables/choices_vs_numeric.rb', line 15 def headers categories = [:quartile_one, :quartile_two, :quartile_three, :quartile_four].collect do |quartile| bucket = @filtered_subjects.send(quartile).collect(&@chart_variable.id.to_sym) "#{bucket.min} to #{bucket.max} #{@chart_variable.units}" end [[""] + categories + ["Total"]] end |
#rows ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/spout/models/tables/choices_vs_numeric.rb', line 34 def rows rows_result = (@variable).collect do |option| row_subjects = @filtered_subjects.select { |s| s.send(@variable.id) == option.value } data = [:quartile_one, :quartile_two, :quartile_three, :quartile_four].collect do |quartile| count = @filtered_subjects.send(quartile).count { |s| s.send(@variable.id) == option.value } Spout::Helpers::TableFormatting.format_number(count, :count) end [option.display_name] + data + [{ text: Spout::Helpers::TableFormatting.format_number(row_subjects.count, :count), style: "font-weight:bold" }] end if @filtered_subjects.count { |s| s.send(@variable.id).is_a?(Spout::Models::Empty) } > 0 unknown_values = [:quartile_one, :quartile_two, :quartile_three, :quartile_four].collect do |quartile| count = @filtered_subjects.send(quartile).count { |s| s.send(@variable.id).is_a?(Spout::Models::Empty) } { text: Spout::Helpers::TableFormatting.format_number(count, :count), class: "text-muted" } end rows_result << [{ text: "Unknown", class: "text-muted"}] + unknown_values + [{ text: Spout::Helpers::TableFormatting.format_number(@filtered_subjects.count { |s| s.send(@variable.id).is_a?(Spout::Models::Empty) }, :count), style: "font-weight:bold", class: "text-muted" }] end rows_result end |
#title ⇒ Object
11 12 13 |
# File 'lib/spout/models/tables/choices_vs_numeric.rb', line 11 def title "#{@variable.display_name} vs #{@chart_variable.display_name}" end |