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
|
# File 'lib/table_analysis.rb', line 6
def self.generator(html, selected_row, *selected_cols)
selected_cols = selected_cols.flatten
doc = Nokogiri::HTML(html, nil, 'utf-8')
table = doc.xpath('//table')[0]
return false if table.nil?
= []
body_content_tds = []
body_tr_size = 0
table.xpath('./tr').each_with_index do |tr, tr_index|
if tr_index == selected_row.to_i - 1
tr.xpath('./td').each do |td|
= td.content
colspan = td.attribute('colspan')&.value
<< [, colspan]
end
elsif tr_index >= selected_row.to_i
body_tr_size += 1
tr.xpath('./td').each_with_index do |td, td_index|
rowspan = td.attribute('rowspan')&.value
colspan = td.attribute('colspan')&.value
body_content_tds << [rowspan, colspan]
end
end
end
= .map do ||
TableAnalysis::.config([0], [1])
end
= TableAnalysis::.config(selected_cols, )
table = TableAnalysis::Table.config(body_tr_size, )
body_tds = body_content_tds.map do |body_td|
TableAnalysis::BodyTd.config(body_td[0], body_td[1])
end
content_maps = TableAnalysis::Core.new(, table, body_tds).entrance
= [Array.new(.size){0}]
table_maps = + content_maps
p table_maps
table_maps
end
|