Class: Spout::Models::Graphables::Default

Inherits:
Object
  • Object
show all
Defined in:
lib/spout/models/graphables/default.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(variable, chart_variable, stratification_variable, subjects) ⇒ Default

Returns a new instance of Default.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/spout/models/graphables/default.rb', line 12

def initialize(variable, chart_variable, stratification_variable, subjects)
  @variable = variable
  @chart_variable = chart_variable
  @stratification_variable = stratification_variable
  @subjects = subjects
  begin
    @values_unique = subjects.collect(&@variable.id.to_sym).reject { |a| a.is_a?(Spout::Models::Empty) }.uniq
  rescue
    @values_unique = []
  end
  @buckets = continuous_buckets
end

Instance Attribute Details

#chart_variableObject (readonly)

Returns the value of attribute chart_variable.



10
11
12
# File 'lib/spout/models/graphables/default.rb', line 10

def chart_variable
  @chart_variable
end

#stratification_variableObject (readonly)

Returns the value of attribute stratification_variable.



10
11
12
# File 'lib/spout/models/graphables/default.rb', line 10

def stratification_variable
  @stratification_variable
end

#subjectsObject (readonly)

Returns the value of attribute subjects.



10
11
12
# File 'lib/spout/models/graphables/default.rb', line 10

def subjects
  @subjects
end

#variableObject (readonly)

Returns the value of attribute variable.



10
11
12
# File 'lib/spout/models/graphables/default.rb', line 10

def variable
  @variable
end

Instance Method Details

#categoriesObject



49
50
51
# File 'lib/spout/models/graphables/default.rb', line 49

def categories
  []
end

#seriesObject



57
58
59
# File 'lib/spout/models/graphables/default.rb', line 57

def series
  []
end

#stackingObject



61
62
63
# File 'lib/spout/models/graphables/default.rb', line 61

def stacking
  nil
end

#subtitleObject



45
46
47
# File 'lib/spout/models/graphables/default.rb', line 45

def subtitle
  "By Visit"
end

#titleObject



41
42
43
# File 'lib/spout/models/graphables/default.rb', line 41

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

#to_hashObject



25
26
27
# File 'lib/spout/models/graphables/default.rb', line 25

def to_hash
  { title: title, subtitle: subtitle, categories: categories, units: units, series: series, stacking: stacking, x_axis_title: x_axis_title } if valid?
end

#unitsObject



53
54
55
# File 'lib/spout/models/graphables/default.rb', line 53

def units
  nil
end

#valid?Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
37
38
39
# File 'lib/spout/models/graphables/default.rb', line 29

def valid?
  if @variable.nil? || @chart_variable.nil? || @values_unique == []
    false
  elsif @variable.type == "choices" && @variable.domain.options == []
    false
  elsif @chart_variable.type == "choices" && @chart_variable.domain.options == []
    false
  else
    true
  end
end

#x_axis_titleObject



65
66
67
# File 'lib/spout/models/graphables/default.rb', line 65

def x_axis_title
  nil
end