Method: Statsample::Crosstab#report_building

Defined in:
lib/statsample/crosstab.rb

#report_building(builder) ⇒ Object


91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/statsample/crosstab.rb', line 91

def report_building(builder)
  builder.section(:name=>@name) do |generator|
    fq=frequencies
    rn=rows_names
    cn=cols_names
    total=0
    total_cols=cols_empty_hash
    generator.text "Chi Square: #{chi_square}"
    generator.text(_("Rows: %s") % @row_label) unless @row_label.nil?
    generator.text(_("Columns: %s") % @column_label) unless @column_label.nil?
    
    t=ReportBuilder::Table.new(:name=>@name+" - "+_("Raw"), :header=>[""]+cols_names.collect {|c| @v_cols.index_of(c)}+[_("Total")])
    rn.each do |row|
      total_row=0
      t_row=[@v_rows.index_of(row)]
      cn.each do |col|
        data=fq[[row,col]]
        total_row+=fq[[row,col]]
        total+=fq[[row,col]]                    
        total_cols[col]+=fq[[row,col]]                    
        t_row.push(data)
      end
      t_row.push(total_row)
      t.row(t_row)
    end
    t.hr
    t_row=[_("Total")]
    cn.each do |v|
      t_row.push(total_cols[v])
    end
    t_row.push(total)
    t.row(t_row)
    generator.parse_element(t)
    
    if(@percentage_row)
      table_percentage(generator,:row)
    end
    if(@percentage_column)
    table_percentage(generator,:column)
    end
    if(@percentage_total)
    table_percentage(generator,:total)
    end
  end
end