table_analysis 0.2.2 → 0.2.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 076263e923dd4735b36a781cdf07d8c4f0c37a7d49ab4c60ae9b33405b186fea
4
- data.tar.gz: d91517297d76c232839ff84c470880de5bf29c41ce5f63d99ac33fda747ad5e5
3
+ metadata.gz: 3584faed5004ee91393970a6d932ec933312e176d92de3cfbda29dd3670e599c
4
+ data.tar.gz: db925f8adbe507bef505b0f8161d5e1c3d9dc120ad13b8ee739d4affa587fdec
5
5
  SHA512:
6
- metadata.gz: 6fac1db553477e6f537a90317d79c76334e436ef7448c69d9f77a6282568f73300e59756c8928d5f9e7c920108cedef072b3213872d9d042d2fec8684cc317a8
7
- data.tar.gz: 84a4acdafbfc33c7709b516bd7e65d99a28bf2e3c30d8f697b36239459fa7c1dec5d6099747623f2be273409d463bc19719dc29b256d481b25c6e2f03384349d
6
+ metadata.gz: 2fb859f85fd1a6872d7c45b011c85ccf122671bb92b9d94465e5aa568267d4381e4f555b91ae1c4074f9f8330a05b7a7f3ec1658dba2e0650a845c4e4e50b32a
7
+ data.tar.gz: 968ae71920bbc66a23c3b01e8e315ea6d6246f3495f74a1935c438ad01fe31a6d935ba6c482fbcc3ff79ac1b726d95086000decb694816fc50575bb8a3b4d348
data/Gemfile.lock CHANGED
@@ -1,12 +1,17 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- table_analysis (0.1.0)
4
+ table_analysis (0.2.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  diff-lcs (1.3)
10
+ mini_portile2 (2.4.0)
11
+ nokogiri (1.10.3)
12
+ mini_portile2 (~> 2.4.0)
13
+ nokogirl (1.0)
14
+ nokogiri
10
15
  rake (10.5.0)
11
16
  rspec (3.8.0)
12
17
  rspec-core (~> 3.8.0)
@@ -27,6 +32,7 @@ PLATFORMS
27
32
 
28
33
  DEPENDENCIES
29
34
  bundler (~> 2.0)
35
+ nokogirl (~> 1.0)
30
36
  rake (~> 10.0)
31
37
  rspec (~> 3.0)
32
38
  table_analysis!
data/demo.rb CHANGED
@@ -2,4 +2,4 @@ require './lib/table_analysis.rb'
2
2
 
3
3
  doc = File.read('file/demo1.html')
4
4
 
5
- TableAnalysis::Main.generator(doc, 2, 1)
5
+ p TableAnalysis::Main.generator(doc, 2, 1)
data/file/demo1.html CHANGED
@@ -1,80 +1,106 @@
1
- <div>
2
- <table style="table-layout: fixed; width: 648px" cellpadding="0" cellspacing="0">
3
- <colgroup>
4
- <col style="width: 101px" />
5
- <col style="width: 101px" />
6
- <col style="width: 101px" />
7
- <col style="width: 101px" />
8
- <col style="width: 127px" />
9
- <col style="width: 117px" />
10
- </colgroup>
11
- <thead>
12
- <tr>
13
- <td style="width: 100px; border-left: 1px solid transparent; border-right: 1px solid transparent" />
14
- <td style="width: 100px; border-left: 1px solid transparent; border-right: 1px solid transparent" />
15
- <td style="width: 100px; border-left: 1px solid transparent; border-right: 1px solid transparent" />
16
- <td style="width: 100px; border-left: 1px solid transparent; border-right: 1px solid transparent" />
17
- <td style="width: 126px; border-left: 1px solid transparent; border-right: 1px solid transparent" />
18
- <td style="border-left: 1px solid transparent; border-right: 1px solid transparent" />
19
- </tr>
20
- <tr style="min-height: 27px">
21
- <td rowspan="2" style="border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: middle">
22
- <p style="line-height: 13.3299999237061px; text-align: center">当期首残高(A)</p>
23
- <p style="line-height: 13.3299999237061px; text-align: center">(千円)</p>
24
- </td>
25
- <td rowspan="2" style="border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: middle">
26
- <p style="line-height: 13.3299999237061px; text-align: center">当期発生高(B)</p>
27
- <p style="line-height: 13.3299999237061px; text-align: center">(千円)</p>
28
- </td>
29
- <td rowspan="2" style="border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: middle">
30
- <p style="line-height: 13.3299999237061px; text-align: center">当期回収高(C)</p>
31
- <p style="line-height: 13.3299999237061px; text-align: center">(千円)</p>
32
- </td>
33
- <td rowspan="2" style="border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px none #000000; border-bottom: 1px solid #000000; vertical-align: middle">
34
- <p style="line-height: 13.3299999237061px; text-align: center">当期末残高</p>
35
- <p style="line-height: 13.3299999237061px; text-align: center">(千円)</p>
36
- </td>
37
- <td style="border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid#000000; vertical-align: middle">
38
- <p style="line-height: 13.3299999237061px; text-align: center">回収率(%)</p>
39
- </td>
40
- <td rowspan="2" style="border-left: 1px none #000000; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: middle">
41
- <p style="line-height: 13.3299999237061px; text-align: center">滞留日数(日)</p>
42
- </td>
43
- </tr>
44
- <tr style="min-height: 40px">
45
- <td style="border-left: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: middle">
46
- <p style="margin-left: 6px; line-height: 1.33000004291534px; text-align: center"> </p>
47
- <div style="text-align: center">
48
- <table style="table-layout: fixed; margin-left: auto; margin-right: auto; width: 100px" cellpadding="0"
49
- cellspacing="0">
50
- <colgroup>
51
- <col style="width: 60px" />
52
- <col style="width: 40px" />
53
- </colgroup>
54
- <tbody>
55
- <tr>
56
- <td style="width: 59px; border-left: 1px solid transparent; border-right: 1px solid transparent" />
57
- <td style="border-left: 1px solid transparent; border-right: 1px solid transparent" />
58
- </tr>
59
- <tr style="min-height: 1.33333337306976px">
60
- <td style="border-left: 0px none #000000; border-top: 0px none #000000; border-right: 0px none #000000; border-bottom: 1px solid #000000; vertical-align: top">
61
- <p style="line-height: 13.3299999237061px; margin-bottom: 1.33000004291534px; text-align: center">
62
- <span style="font-size: 12px">C</span>
63
- </p>
64
- </td>
65
- <td rowspan="2" style="border-top: 0px none #000000; border-right: 0px none #000000; border-bottom: 0px none #000000; vertical-align: middle">
66
- <p style="margin-left: 4px; line-height: 13.3299999237061px; text-align: center">
67
- <span style="font-size: 12px">×100</span>
68
- </p>
69
- </td>
70
- </tr>
71
- <tr style="min-height: 1.33333337306976px">
72
- <td style="border-left: 0px none #000000; border-top: 1px solid #000000; border-right: 0px none #000000; border-bottom: 0px none #000000; vertical-align: top">
73
- <p style="line-height: 13.3299999237061px; margin-top: 1.33000004291534px; text-align: center">
74
- <span style="font-size: 12px">A+B</span>
75
- </p>
76
- </td>
77
- </tr>
78
- </tbody>
79
- </table>
80
- </div>
1
+ <table style="table-layout: fixed; width: 648px" cellpadding="0" cellspacing="0">
2
+ <colgroup>
3
+ <col style="width: 101px">
4
+ <col style="width: 101px">
5
+ <col style="width: 101px">
6
+ <col style="width: 101px">
7
+ <col style="width: 127px">
8
+ <col style="width: 117px">
9
+ </colgroup>
10
+ <thead>
11
+ <tr>
12
+ <td style="width: 100px; border-left: 1px solid transparent; border-right: 1px solid transparent"></td>
13
+ <td style="width: 100px; border-left: 1px solid transparent; border-right: 1px solid transparent"></td>
14
+ <td style="width: 100px; border-left: 1px solid transparent; border-right: 1px solid transparent"></td>
15
+ <td style="width: 100px; border-left: 1px solid transparent; border-right: 1px solid transparent"></td>
16
+ <td style="width: 126px; border-left: 1px solid transparent; border-right: 1px solid transparent"></td>
17
+ <td style="border-left: 1px solid transparent; border-right: 1px solid transparent"></td>
18
+ </tr>
19
+ <tr style="min-height: 27px">
20
+ <td rowspan="2" style="border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: middle">
21
+ <p style="line-height: 13.3299999237061px; text-align: center">当期首残高(A)</p>
22
+ <p style="line-height: 13.3299999237061px; text-align: center">(千円)</p>
23
+ </td>
24
+ <td rowspan="2" style="border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: middle">
25
+ <p style="line-height: 13.3299999237061px; text-align: center">当期発生高(B)</p>
26
+ <p style="line-height: 13.3299999237061px; text-align: center">(千円)</p>
27
+ </td>
28
+ <td rowspan="2" style="border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: middle">
29
+ <p style="line-height: 13.3299999237061px; text-align: center">当期回収高(C)</p>
30
+ <p style="line-height: 13.3299999237061px; text-align: center">(千円)</p>
31
+ </td>
32
+ <td rowspan="2" style="border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px none #000000; border-bottom: 1px solid #000000; vertical-align: middle">
33
+ <p style="line-height: 13.3299999237061px; text-align: center">当期末残高</p>
34
+ <p style="line-height: 13.3299999237061px; text-align: center">(千円)</p>
35
+ </td>
36
+ <td style="border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid#000000; vertical-align: middle">
37
+ <p style="line-height: 13.3299999237061px; text-align: center">回収率(%)</p>
38
+ </td>
39
+ <td rowspan="2" style="border-left: 1px none #000000; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: middle">
40
+ <p style="line-height: 13.3299999237061px; text-align: center">滞留日数(日)</p>
41
+ </td>
42
+ </tr>
43
+ <tr style="min-height: 40px">
44
+ <td style="border-left: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: middle">
45
+ <p style="margin-left: 6px; line-height: 1.33000004291534px; text-align: center"> </p>
46
+ <div style="text-align: center">
47
+ <table style="table-layout: fixed; margin-left: auto; margin-right: auto; width: 100px" cellpadding="0"
48
+ cellspacing="0">
49
+ <colgroup>
50
+ <col style="width: 60px">
51
+ <col style="width: 40px">
52
+ </colgroup>
53
+ <tbody>
54
+ <tr>
55
+ <td style="width: 59px; border-left: 1px solid transparent; border-right: 1px solid transparent"></td>
56
+ <td style="border-left: 1px solid transparent; border-right: 1px solid transparent"></td>
57
+ </tr>
58
+ <tr style="min-height: 1.33333337306976px">
59
+ <td style="border-left: 0px none #000000; border-top: 0px none #000000; border-right: 0px none #000000; border-bottom: 1px solid #000000; vertical-align: top">
60
+ <p style="line-height: 13.3299999237061px; margin-bottom: 1.33000004291534px; text-align: center">
61
+ <span style="font-size: 12px">C</span>
62
+ </p>
63
+ </td>
64
+ <td rowspan="2" style="border-top: 0px none #000000; border-right: 0px none #000000; border-bottom: 0px none #000000; vertical-align: middle">
65
+ <p style="margin-left: 4px; line-height: 13.3299999237061px; text-align: center">
66
+ <span style="font-size: 12px">×100</span>
67
+ </p>
68
+ </td>
69
+ </tr>
70
+ <tr style="min-height: 1.33333337306976px">
71
+ <td style="border-left: 0px none #000000; border-top: 1px solid #000000; border-right: 0px none #000000; border-bottom: 0px none #000000; vertical-align: top">
72
+ <p style="line-height: 13.3299999237061px; margin-top: 1.33000004291534px; text-align: center">
73
+ <span style="font-size: 12px">A+B</span>
74
+ </p>
75
+ </td>
76
+ </tr>
77
+ </tbody>
78
+ </table>
79
+ </div>
80
+ <p style="margin-left: 6px; line-height: 1.33000004291534px; text-align: center"> </p>
81
+ </td>
82
+ </tr>
83
+ </thead>
84
+ <tbody>
85
+ <tr style="min-height: 27px">
86
+ <td style="border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid#000000; border-bottom: 1px solid #000000; vertical-align: middle">
87
+ <p style="margin-right: 12px; text-align: right">5,398,815</p>
88
+ </td>
89
+ <td style="border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid#000000; border-bottom: 1px solid #000000; vertical-align: middle">
90
+ <p style="margin-right: 12px; text-align: right">31,968,312</p>
91
+ </td>
92
+ <td style="border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid#000000; border-bottom: 1px solid #000000; vertical-align: middle">
93
+ <p style="margin-right: 12px; text-align: right">31,817,515</p>
94
+ </td>
95
+ <td style="border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid#000000; border-bottom: 1px solid #000000; vertical-align: middle">
96
+ <p style="margin-right: 12px; text-align: right">5,549,613</p>
97
+ </td>
98
+ <td style="border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid#000000; border-bottom: 1px solid #000000; vertical-align: middle">
99
+ <p style="margin-right: 18px; text-align: right">85.15</p>
100
+ </td>
101
+ <td style="border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid#000000; border-bottom: 1px solid #000000; vertical-align: middle">
102
+ <p style="margin-right: 18px; text-align: right">62.50</p>
103
+ </td>
104
+ </tr>
105
+ </tbody>
106
+ </table>
@@ -11,15 +11,25 @@ module TableAnalysis
11
11
  return false if table.nil?
12
12
  header_content_tds = []
13
13
  body_content_tds = []
14
+ header_body_content_tds = []
14
15
  body_tr_size = 0
15
- table.xpath('.//tr').each_with_index do |tr, tr_index|
16
+ tr_rows = 1
17
+ table.xpath('./thead/tr|./tbody/tr').each_with_index do |tr, tr_index|
16
18
  if tr_index == selected_row.to_i - 1
17
19
  tr.xpath('./td').each do |td|
18
- header_name = td.content
19
20
  colspan = td.attribute('colspan')&.value
20
- header_content_tds << [header_name, colspan]
21
+ rowspan = td.attribute('rowspan')&.value
22
+ header_content_tds << [rowspan, colspan]
23
+ header_body_content_tds << [rowspan, colspan]
24
+ tr_rows = rowspan.to_i.dup if !rowspan.nil? && rowspan.to_i > 1 && tr_rows < rowspan.to_i
21
25
  end
22
- elsif tr_index >= selected_row.to_i
26
+ elsif tr_index > selected_row.to_i - 1 && tr_index < selected_row.to_i - 1 + tr_rows
27
+ tr.xpath('./td').each do |td|
28
+ rowspan = td.attribute('rowspan')&.value
29
+ colspan = td.attribute('colspan')&.value
30
+ header_body_content_tds << [rowspan, colspan]
31
+ end
32
+ elsif tr_index >= selected_row.to_i - 1 + tr_rows
23
33
  body_tr_size += 1
24
34
  tr.xpath('./td').each_with_index do |td, td_index|
25
35
  rowspan = td.attribute('rowspan')&.value
@@ -34,17 +44,22 @@ module TableAnalysis
34
44
  end
35
45
 
36
46
  header = TableAnalysis::Header.config(selected_cols, header_tds)
37
- table = TableAnalysis::Table.config(body_tr_size, header)
38
47
 
48
+ table = TableAnalysis::Table.config(body_tr_size, header)
39
49
  body_tds = body_content_tds.map do |body_td|
40
50
  TableAnalysis::BodyTd.config(body_td[0], body_td[1])
41
51
  end
42
52
 
43
53
  content_maps = TableAnalysis::Core.new(header, table, body_tds).entrance
44
54
 
45
- header_map = [Array.new(header_tds.size){0}]
55
+ header_table = TableAnalysis::Table.config(tr_rows, header)
56
+ header_body_tds = header_body_content_tds.map do |body_td|
57
+ TableAnalysis::BodyTd.config(body_td[0], body_td[1])
58
+ end
59
+
60
+ header_maps = TableAnalysis::Core.new(header, header_table, header_body_tds).entrance
46
61
 
47
- table_maps = header_map + content_maps
62
+ table_maps = header_maps + content_maps
48
63
 
49
64
  table_maps
50
65
  end
@@ -14,15 +14,15 @@ module TableAnalysis
14
14
  end
15
15
 
16
16
  class HeaderTd
17
- attr_accessor :name, :length
17
+ attr_accessor :rowspan, :length
18
18
 
19
- def initialize(name, length)
20
- @name = name.delete('\n').strip
19
+ def initialize(rowspan, length)
20
+ @rowspan = rowspan.nil? ? 1 : rowspan.to_i
21
21
  @length = length.nil? ? 1 : length.to_i
22
22
  end
23
23
 
24
- def self.config(name, length)
25
- new(name, length)
24
+ def self.config(rowspan, length)
25
+ new(rowspan, length)
26
26
  end
27
27
  end
28
28
  end
@@ -1,3 +1,3 @@
1
1
  module TableAnalysis
2
- VERSION = '0.2.2'.freeze
2
+ VERSION = '0.2.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: table_analysis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - mico_xiaozhen@sina.com
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-10 00:00:00.000000000 Z
11
+ date: 2019-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler