Class: Spout::Models::Tables::Default
- Inherits:
-
Object
- Object
- Spout::Models::Tables::Default
- Defined in:
- lib/spout/models/tables/default.rb
Direct Known Subclasses
ChoicesVsChoices, ChoicesVsNumeric, NumericVsChoices, NumericVsNumeric
Instance Attribute Summary collapse
-
#chart_variable ⇒ Object
readonly
Returns the value of attribute chart_variable.
-
#subjects ⇒ Object
readonly
Returns the value of attribute subjects.
-
#subtitle ⇒ Object
readonly
Returns the value of attribute subtitle.
-
#totals ⇒ Object
readonly
Returns the value of attribute totals.
-
#variable ⇒ Object
readonly
Returns the value of attribute variable.
Instance Method Summary collapse
- #footers ⇒ Object
- #headers ⇒ Object
-
#initialize(variable, chart_variable, subjects, subtitle, totals) ⇒ Default
constructor
A new instance of Default.
- #rows ⇒ Object
- #title ⇒ Object
- #to_hash ⇒ Object
-
#valid? ⇒ Boolean
TODO: Same as graphables/default.rb REFACTOR.
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_variable ⇒ Object (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 |
#subjects ⇒ Object (readonly)
Returns the value of attribute subjects.
10 11 12 |
# File 'lib/spout/models/tables/default.rb', line 10 def subjects @subjects end |
#subtitle ⇒ Object (readonly)
Returns the value of attribute subtitle.
10 11 12 |
# File 'lib/spout/models/tables/default.rb', line 10 def subtitle @subtitle end |
#totals ⇒ Object (readonly)
Returns the value of attribute totals.
10 11 12 |
# File 'lib/spout/models/tables/default.rb', line 10 def totals @totals end |
#variable ⇒ Object (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
#footers ⇒ Object
54 55 56 |
# File 'lib/spout/models/tables/default.rb', line 54 def [] end |
#headers ⇒ Object
50 51 52 |
# File 'lib/spout/models/tables/default.rb', line 50 def headers [] end |
#rows ⇒ Object
58 59 60 |
# File 'lib/spout/models/tables/default.rb', line 58 def rows [] end |
#title ⇒ Object
46 47 48 |
# File 'lib/spout/models/tables/default.rb', line 46 def title "" end |
#to_hash ⇒ Object
29 30 31 |
# File 'lib/spout/models/tables/default.rb', line 29 def to_hash { title: title, subtitle: @subtitle, headers: headers, footers: , rows: rows } if valid? end |
#valid? ⇒ Boolean
TODO: Same as graphables/default.rb REFACTOR
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. == [] false elsif @chart_variable.type == "choices" && @chart_variable.domain. == [] false else true end end |