Class: Crosstab::Table
Instance Method Summary collapse
-
#group(name = nil, &block) ⇒ Object
DSL child setter, creates a new Group, and rows created within its block will be assigned to that group.
-
#initialize(&block) ⇒ Table
constructor
Pass in a block and we’ll execute it within the context of this class.
-
#row(name, qualification) ⇒ Object
Creates a new Crosstab::Row and appends it to the rows array.
-
#rows ⇒ Object
attr_reader for the rows attribute which should contain an empty array, or a list of rows.
Methods inherited from Generic
#printed?, #qualification, #qualifies?, #title
Constructor Details
#initialize(&block) ⇒ Table
13 14 15 |
# File 'lib/crosstab/table.rb', line 13 def initialize(&block) instance_eval(&block) if block end |
Instance Method Details
#group(name = nil, &block) ⇒ Object
DSL child setter, creates a new Group, and rows created within its block will be assigned to that group.
Example:
rows
#=> []
group "Gender" do
row "Male", :a => 1
row "Female", :a => 2
end
rows
#=> [Crosstab::Row..., Crosstab::Row...]
rows[0].group.title
# => "Gender"
rows[1].group.title
# => "Gender"
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/crosstab/table.rb', line 70 def group(name=nil, &block) if block old_rows = rows.dup # Save current state instance_eval(&block) # Execute block within current scope g = Crosstab::Group.new(name) # Create new group # Set group for all of the new rows (rows - old_rows).each do |row| row.group g end end end |
#row(name, qualification) ⇒ Object
Creates a new Crosstab::Row and appends it to the rows array.
Example:
rows
#=> []
row "Male", :a => 1
rows
#=> [Crosstab::Row...]
45 46 47 |
# File 'lib/crosstab/table.rb', line 45 def row(name,qualification) rows << Crosstab::Row.new(name, qualification) end |
#rows ⇒ Object
attr_reader for the rows attribute which should contain an empty array, or a list of rows
Example:
rows
#=> []
row "Male", :a => 1
rows
#=> [Crosstab::Row...]
29 30 31 |
# File 'lib/crosstab/table.rb', line 29 def rows @rows ||= [] end |