tablestructured 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tablestructured.rb +14 -3
- data/tablestructured.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5c9006b6d4ebf186aa8724d2dfa389a70f44bed
|
4
|
+
data.tar.gz: b0d01cc440f469ecff3c49420b2c35a24eb84c19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 355ee52c41d87fde5a2a28480223abfbe6efe7d63eee84b88ded1efcd9b58a5eb54fdcf92614db43263620ab68b0a55bec4e29c90363dd6adc1bd76aaf9d12fa
|
7
|
+
data.tar.gz: 9716ee1c7b6bd0874f896341e94110bee09234421351476d9bae2ba294e9fda0472c3ae335d860d79f432c4b55c3432b630303653fde9961ce8e2bad1a0cdf97
|
data/lib/tablestructured.rb
CHANGED
@@ -1,9 +1,20 @@
|
|
1
1
|
module TableStructured
|
2
|
-
def self.new object, headers: :top # TODO: headers_left should probably mean the ids of entries
|
2
|
+
def self.new object, headers: :top, drop: 0 # TODO: headers_left should probably mean the ids of entries
|
3
3
|
if object.respond_to? :css
|
4
4
|
# the xml object ignores the :headers arg for now
|
5
|
-
|
6
|
-
|
5
|
+
ss = if :top == headers
|
6
|
+
object
|
7
|
+
elsif headers.respond_to? :css
|
8
|
+
headers
|
9
|
+
else
|
10
|
+
fail "invalid type of headers"
|
11
|
+
end.css("th").drop(drop).map{ |_| _.text.sub(/\A[[[:space:]]]*/,"").sub(/[[[:space:]]]*\z/,"").to_sym }
|
12
|
+
struct = begin
|
13
|
+
Struct.new *ss
|
14
|
+
rescue NameError
|
15
|
+
raise $!.exception "#{$!}: #{ss.inspect}"
|
16
|
+
end
|
17
|
+
object.css("tbody>tr").map{ |_| struct.new *_.css("td").drop(drop) }
|
7
18
|
else
|
8
19
|
struct = Struct.new *object.first.map(&:to_s).map(&:to_sym).tap{ |_| fail "headers should be unique" if _.uniq! }
|
9
20
|
object.drop(1).map{ |_| struct.new *_ }
|
data/tablestructured.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "tablestructured"
|
3
|
-
spec.version = "0.1.
|
3
|
+
spec.version = "0.1.2"
|
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.1.
|
4
|
+
version: 0.1.2
|
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: 2022-07-
|
11
|
+
date: 2022-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: nakilon@gmail.com
|