2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/udise_school_report_reader/enrollment_html_writer.rb', line 2
def self.generate_html(data, html_path)
return unless data
grade_rows = data[:grade_rows]
bg_pairs = data[:bg_pairs]
categories = [
['Gen', data[:gen_numbers]],
['SC', data[:sc_numbers]],
['ST', data[:st_numbers]],
['OBC', data[:obc_numbers]],
['Muslim', data[:musl_numbers]],
['Christian', data[:chris_numbers]],
['Sikh', data[:sikh_numbers]],
['Buddhist', data[:budd_numbers]],
['Parsi', data[:parsi_numbers]],
['Jain', data[:jain_numbers]],
['Others', data[:others_numbers]],
['Aadhaar', data[:aadh_numbers]],
['BPL', data[:bpl_numbers]],
['Repeater', data[:rept_numbers]],
['CWSN', data[:cwsn_numbers]]
]
ages = (3..22).map do |age|
["Age #{age}", data[:"age_#{age}_numbers"]]
end
table_rows = (categories + ages).map do |category, numbers|
cells = bg_pairs.map do |x_mid, _|
nums = numbers[x_mid]
b_num = nums&.first
g_num = nums&.last
"<td>#{b_num ? b_num['text'] : ''}</td><td>#{g_num ? g_num['text'] : ''}</td>"
end.join
" <tr>\n" \
" <td class=\"category\">#{category}</td>\n" \
" #{cells}\n" \
" </tr>"
end.join("\n")
= grade_rows.map { |row| "<th colspan='2'>#{row['text']}</th>" }.join
= grade_rows.map { |_| "<td>B</td><td>G</td>" }.join
html_content = " <!DOCTYPE html>\n <html>\n <head>\n <title>Enrollment Table</title>\n <style>\n table { border-collapse: collapse; margin-top: 20px; width: 100%; }\n th, td { border: 1px solid black; padding: 8px; text-align: center; }\n .header { font-weight: bold; background-color: #f0f0f0; }\n .grade { font-weight: bold; background-color: #e0e0e0; }\n .bg-pair { background-color: #f8f8f8; }\n .category { font-weight: bold; text-align: left; }\n </style>\n </head>\n <body>\n <h2>Enrolment (By Social Category)</h2>\n <table>\n <tr class=\"grade\">\n <th rowspan=\"2\">Category</th>\n \#{grade_headers}\n </tr>\n <tr class=\"bg-pair\">\n \#{bg_headers}\n </tr>\n \#{table_rows}\n </table>\n </body>\n </html>\n HTML\n\n File.write(html_path, html_content)\nend\n"
|