table_analysis 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/demo.rb +1 -1
- data/file/demo2.html +8 -0
- data/lib/table_analysis/version.rb +1 -1
- data/lib/table_analysis.rb +4 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9bf918d52ccc29e84ca90d77bd5e0f46946d4fc960e22bd81d6552459fbf236
|
4
|
+
data.tar.gz: 0a07dd387dc71a76ee60b40d64e501eac515cbb3e0db6ec1a2de57f980694baa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7adf1b44623efce822185d8b45b6d2f0cb9d8ae0da74d39a99fa74ddb621e454276096740cbd0353829e8d7ef2744a03d48bfc18e7b974720ac2e917ae23a578
|
7
|
+
data.tar.gz: 7683f2c480e3d956a9c61901f3cef32922323c6c080c2291178222a08f4df430436eae50123e2ef604f3f3ffdec6d871954373ca3838b619a65021ec7bb74e8f
|
data/demo.rb
CHANGED
data/file/demo2.html
CHANGED
@@ -10,6 +10,14 @@
|
|
10
10
|
<col style="width:139.5pt;min-width:139.5pt;"/>
|
11
11
|
<col style="width:105pt;min-width:105pt;"/>
|
12
12
|
</colgroup>
|
13
|
+
<tr style="height:21.8pt">
|
14
|
+
<td valign="middle" style="vertical-align:middle;border-top-style:solid;border-top-width:0.75pt;border-bottom-style:solid;border-bottom-width:0.75pt;border-left-style:solid;border-left-width:0.75pt;border-right-style:solid;border-right-width:0.75pt;">
|
15
|
+
<p class="smt_tblC">1</p>
|
16
|
+
</td>
|
17
|
+
<td valign="middle" style="vertical-align:middle;border-top-style:solid;border-top-width:0.75pt;border-bottom-style:solid;border-bottom-width:0.75pt;border-left-style:solid;border-left-width:0.75pt;border-right-style:solid;border-right-width:0.75pt;">
|
18
|
+
<p class="smt_tblC">2</p>
|
19
|
+
</td>
|
20
|
+
</tr>
|
13
21
|
<tr style="height:21.8pt">
|
14
22
|
<td valign="middle" style="vertical-align:middle;border-top-style:solid;border-top-width:0.75pt;border-bottom-style:solid;border-bottom-width:0.75pt;border-left-style:solid;border-left-width:0.75pt;border-right-style:solid;border-right-width:0.75pt;">
|
15
23
|
<p class="smt_tblC">契約会社名</p>
|
data/lib/table_analysis.rb
CHANGED
@@ -3,23 +3,23 @@ require_relative 'table_analysis/version'
|
|
3
3
|
require 'nokogiri'
|
4
4
|
module TableAnalysis
|
5
5
|
class Main
|
6
|
-
def self.generator(html, *selected_cols)
|
6
|
+
def self.generator(html, selected_row, *selected_cols)
|
7
7
|
selected_cols = selected_cols.flatten
|
8
8
|
doc = Nokogiri::HTML(html, nil, 'utf-8')
|
9
9
|
# 多个table,仅处理第一个
|
10
10
|
table = doc.xpath('//table')[0]
|
11
|
-
return false if table.
|
11
|
+
return false if table.nil?
|
12
12
|
header_content_tds = []
|
13
13
|
body_content_tds = []
|
14
14
|
body_tr_size = 0
|
15
15
|
table.xpath('./tr').each_with_index do |tr, tr_index|
|
16
|
-
if tr_index ==
|
16
|
+
if tr_index == selected_row.to_i - 1
|
17
17
|
tr.xpath('./td').each do |td|
|
18
18
|
header_name = td.content
|
19
19
|
colspan = td.attribute('colspan')&.value
|
20
20
|
header_content_tds << [header_name, colspan]
|
21
21
|
end
|
22
|
-
|
22
|
+
elsif tr_index >= selected_row.to_i
|
23
23
|
body_tr_size += 1
|
24
24
|
tr.xpath('./td').each_with_index do |td, td_index|
|
25
25
|
rowspan = td.attribute('rowspan')&.value
|