class Spout::Models::Tables::Default
Attributes
chart_variable[R]
subjects[R]
subtitle[R]
totals[R]
variable[R]
Public Class Methods
new(variable, chart_variable, subjects, subtitle, totals)
click to toggle source
# File lib/spout/models/tables/default.rb, line 12 def initialize(variable, chart_variable, subjects, subtitle, totals) @variable = variable @chart_variable = chart_variable @subtitle = subtitle @totals = totals begin @filtered_subjects = subjects.reject { |s| s.send(@chart_variable.id).is_a?(Spout::Models::Empty) }.sort_by(&@chart_variable.id.to_sym) rescue @filtered_subjects = [] end begin @values_unique = @filtered_subjects.collect(&@variable.id.to_sym).uniq rescue @values_unique = [] end end
Public Instance Methods
headers()
click to toggle source
# File lib/spout/models/tables/default.rb, line 50 def headers [] end
rows()
click to toggle source
# File lib/spout/models/tables/default.rb, line 58 def rows [] end
title()
click to toggle source
# File lib/spout/models/tables/default.rb, line 46 def title "" end
to_hash()
click to toggle source
# File lib/spout/models/tables/default.rb, line 29 def to_hash { title: title, subtitle: @subtitle, headers: headers, footers: footers, rows: rows } if valid? end
valid?()
click to toggle source
TODO: Same as graphables/default.rb REFACTOR
# File lib/spout/models/tables/default.rb, line 34 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
Private Instance Methods
filtered_domain_options(variable)
click to toggle source
Returns variable options that are either: a) are not missing codes b) or are marked as missing codes but represented in the dataset
# File lib/spout/models/tables/default.rb, line 67 def filtered_domain_options(variable) variable.domain.options.select do |o| o.missing != true || (o.missing == true && @values_unique.include?(o.value)) end end