Class: Crosstab::Row
Direct Known Subclasses
Instance Method Summary collapse
-
#cells(value = nil) ⇒ Object
attr_reader for the cells attribute which should contain an empty array, or – if calculate was called on the crosstab – this will contain an array of cells, one for each column in the banner.
-
#group(g = nil) ⇒ Object
DSL accessor for the group attribute.
-
#initialize(label = nil, qual = nil) ⇒ Row
constructor
A new instance of Row.
Methods inherited from Generic
#printed?, #qualification, #qualifies?, #title
Constructor Details
#initialize(label = nil, qual = nil) ⇒ Row
Returns a new instance of Row.
2 3 4 5 |
# File 'lib/crosstab/row.rb', line 2 def initialize(label=nil, qual=nil) title label if label qualification qual if qual end |
Instance Method Details
#cells(value = nil) ⇒ Object
attr_reader for the cells attribute which should contain an empty array, or – if calculate was called on the crosstab – this will contain an array of cells, one for each column in the banner.
Example:
my_crosstab = Crosstab::Crosstab.new do
data_source [{:a => 1}, {:a => 2}]
table do
title "Q.A Gender:"
row "Male", :a => 1
row "Female", :a => 2
end
end
my_crosstab.calculate
my_crosstab.tables[0].rows[0].title
# => "Male"
my_crosstab.tables[0].rows[0].cells[0].frequency
# => 1
my_crosstab.tables[0].rows[0].cells[0].base
# => 2
my_crosstab.tables[0].rows[0].cells[0].percentage
# => 0.5
36 37 38 39 40 41 42 |
# File 'lib/crosstab/row.rb', line 36 def cells(value=nil) if value @cells = value else @cells ||= [] end end |
#group(g = nil) ⇒ Object
DSL accessor for the group attribute
Example:
group
# => nil
group Crosstab::Group.new("Gender")
# => Crosstab::Group...
group.title
# => "Gender"
57 58 59 60 61 62 63 64 |
# File 'lib/crosstab/row.rb', line 57 def group(g=nil) if g @group = g g.children << self # Add self to its list of children else @group ||= nil end end |