tablestructured 0.2.0 → 0.3.0
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 +5 -5
- data/lib/tablestructured.rb +10 -5
- data/tablestructured.gemspec +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a18246ac024ad7427f265067f356a4e8b7ef1dc368a3648588f16b20a29fc8c0
|
4
|
+
data.tar.gz: 8d7879c11f295400cab85f894b32ab09d6919b62d3613c412a742f8b699aee95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3eb3f0131ed50ea19405dd47e5164d3ed61d28cfcb67119787ecea019c64d26273371dde7546a156dd4d49049d73c971743a17af0091ca3e60f1ee13bdece72
|
7
|
+
data.tar.gz: 87c75e478c0f7c806c18d7d0d1a7b6d17f2d409b38752de8989f0d6468d96c459c2cf24f626ef5711027b9fd665e863b23ac841908257c197985d6ac2c52f90e
|
data/lib/tablestructured.rb
CHANGED
@@ -5,18 +5,23 @@ module TableStructured
|
|
5
5
|
raise ArgumentError, "passed object can be an Array or Ferrum Node, but not Nil"
|
6
6
|
elsif object.respond_to? :css
|
7
7
|
# the xml object ignores the :headers arg for now
|
8
|
-
|
8
|
+
names = if :top == headers
|
9
9
|
object
|
10
10
|
elsif headers.respond_to? :css
|
11
11
|
headers
|
12
12
|
else
|
13
13
|
fail "invalid type of headers"
|
14
|
-
end.css("th")[drop_first..-1-drop_last].map
|
14
|
+
end.css("th")[drop_first..-1-drop_last].map do |_|
|
15
|
+
_.text.sub(/\A[[[:space:]]]*/,"").sub(/[[[:space:]]]*\z/,"")
|
16
|
+
end
|
17
|
+
t = names.group_by(&:itself).map{ |k, g| [k, g.size.times.to_a] if 1 < g.size }.compact.to_h
|
18
|
+
names = names.map{ |_| if i = t[_]&.shift then "#{_}_#{i+1}" else _ end.to_sym }
|
15
19
|
struct = begin
|
16
|
-
Struct.new *
|
20
|
+
Struct.new *names
|
17
21
|
rescue NameError
|
18
|
-
raise $!.exception "#{$!}: #{
|
22
|
+
raise $!.exception "#{$!}: #{names.inspect}"
|
19
23
|
end
|
24
|
+
require "timeout"
|
20
25
|
object.css("tbody>tr").map do |_|
|
21
26
|
tds = []
|
22
27
|
Timeout.timeout 2 do
|
@@ -27,7 +32,7 @@ module TableStructured
|
|
27
32
|
redo
|
28
33
|
end
|
29
34
|
end
|
30
|
-
raise Error, "size mismatch (#{
|
35
|
+
raise Error, "size mismatch (#{names.size} headers, #{tds.size} row items)" if tds.size != names.size
|
31
36
|
struct.new *tds
|
32
37
|
end
|
33
38
|
else
|
data/tablestructured.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "tablestructured"
|
3
|
-
spec.version = "0.
|
3
|
+
spec.version = "0.3.0"
|
4
4
|
spec.summary = "convert two-dimensional Array into an Array of Structs consuming the first row and/or column as attributes"
|
5
5
|
|
6
6
|
spec.author = "Victor Maslov aka Nakilon"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tablestructured
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Maslov aka Nakilon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: nakilon@gmail.com
|
@@ -39,8 +39,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
requirements: []
|
42
|
-
|
43
|
-
rubygems_version: 2.5.2.3
|
42
|
+
rubygems_version: 3.3.25
|
44
43
|
signing_key:
|
45
44
|
specification_version: 4
|
46
45
|
summary: convert two-dimensional Array into an Array of Structs consuming the first
|