tablestructured 0.2.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/tablestructured.rb +13 -8
- 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: 12d89b2a0cfe64d0e225df5f48039f6eb3a57a7f9ff6fd930e996d0ff1165b50
|
4
|
+
data.tar.gz: ee0b66891ddfe222331030ef454485af24485098b7ad00e3babbcebe42348925
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 632a6b7642ffa08a59a7b8930ff414dcb5c5760307d432eb8581a779f9889b2b52f869e5292e54119dbd829b329835f464413842b91ad750224fe938b63049ab
|
7
|
+
data.tar.gz: b9ab937ba3227e6972b45c978d62e62eb6d2ff9696beeb5d9967f675a49bfbaff15cc4de8395d4a66a1439c0615a009918bc27f2a43d3cfa8a283b12e2f87b27
|
data/lib/tablestructured.rb
CHANGED
@@ -5,29 +5,34 @@ 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("thead 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
|
20
|
-
|
24
|
+
require "timeout"
|
25
|
+
object.css("tbody > tr").map do |row|
|
21
26
|
tds = []
|
22
|
-
Timeout.timeout
|
23
|
-
tds =
|
27
|
+
Timeout.timeout 5 do
|
28
|
+
tds = [row.css("th"), *row.css("td")][drop_first..-1-drop_last]
|
24
29
|
if tds.empty?
|
25
30
|
STDERR.puts "empty row"
|
26
31
|
sleep 0.1
|
27
32
|
redo
|
28
33
|
end
|
29
34
|
end
|
30
|
-
raise Error, "size mismatch (#{
|
35
|
+
raise Error, "size mismatch (#{names.size} headers (#{names}), #{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.4.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.4.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-06-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.2.3
|
44
43
|
signing_key:
|
45
44
|
specification_version: 4
|
46
45
|
summary: convert two-dimensional Array into an Array of Structs consuming the first
|