Module: Spout::Models::Graphables

Defined in:
lib/spout/models/graphables.rb,
lib/spout/models/graphables/default.rb,
lib/spout/models/graphables/histogram.rb,
lib/spout/models/graphables/choices_vs_choices.rb,
lib/spout/models/graphables/choices_vs_numeric.rb,
lib/spout/models/graphables/numeric_vs_choices.rb,
lib/spout/models/graphables/numeric_vs_numeric.rb

Defined Under Namespace

Classes: ChoicesVsChoices, ChoicesVsNumeric, Default, Histogram, NumericVsChoices, NumericVsNumeric

Constant Summary collapse

DEFAULT_CLASS =
Spout::Models::Graphables::Default
GRAPHABLE_CLASSES =
{
  "histogram" =>          Spout::Models::Graphables::Histogram,
  "numeric_vs_choices" => Spout::Models::Graphables::NumericVsChoices,
  "choices_vs_choices" => Spout::Models::Graphables::ChoicesVsChoices,
  "numeric_vs_numeric" => Spout::Models::Graphables::NumericVsNumeric,
  "choices_vs_numeric" => Spout::Models::Graphables::ChoicesVsNumeric
}

Class Method Summary collapse

Class Method Details

.for(variable, chart_variable, stratification_variable, subjects) ⇒ Object



22
23
24
25
# File 'lib/spout/models/graphables.rb', line 22

def self.for(variable, chart_variable, stratification_variable, subjects)
  graph_type = get_graph_type(variable, chart_variable, stratification_variable)
  (GRAPHABLE_CLASSES[graph_type] || DEFAULT_CLASS).new(variable, chart_variable, stratification_variable, subjects)
end

.get_graph_type(variable, chart_variable, stratification_variable) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/spout/models/graphables.rb', line 27

def self.get_graph_type(variable, chart_variable, stratification_variable)
  if stratification_variable.nil?
    "histogram"
  else
    "#{variable_to_graph_type(variable)}_vs_#{variable_to_graph_type(chart_variable)}"
  end
end

.variable_to_graph_type(variable) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/spout/models/graphables.rb', line 35

def self.variable_to_graph_type(variable)
  variable_type = (variable ? variable.type : nil)
  case variable_type
  when "numeric", "integer"
    "numeric"
  else
    variable_type
  end
end