Class: Spout::Models::Tables::Default

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(variable, chart_variable, subjects, subtitle, totals) ⇒ Default

Returns a new instance of Default.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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

Instance Attribute Details

#chart_variableObject (readonly)

Returns the value of attribute chart_variable.



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

def chart_variable
  @chart_variable
end

#subjectsObject (readonly)

Returns the value of attribute subjects.



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

def subjects
  @subjects
end

#subtitleObject (readonly)

Returns the value of attribute subtitle.



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

def subtitle
  @subtitle
end

#totalsObject (readonly)

Returns the value of attribute totals.



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

def totals
  @totals
end

#variableObject (readonly)

Returns the value of attribute variable.



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

def variable
  @variable
end

Instance Method Details

#footersObject



54
55
56
# File 'lib/spout/models/tables/default.rb', line 54

def footers
  []
end

#headersObject



50
51
52
# File 'lib/spout/models/tables/default.rb', line 50

def headers
  []
end

#rowsObject



58
59
60
# File 'lib/spout/models/tables/default.rb', line 58

def rows
  []
end

#titleObject



46
47
48
# File 'lib/spout/models/tables/default.rb', line 46

def title
  ""
end

#to_hashObject



29
30
31
# 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?Boolean

TODO: Same as graphables/default.rb REFACTOR

Returns:

  • (Boolean)


34
35
36
37
38
39
40
41
42
43
44
# 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