tablestructured 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eff8ab5fd48d7f513a36a9c62a33a97bf21266b5
4
- data.tar.gz: 4fe70c614965faa1f76f717be42f5444ae51e348
3
+ metadata.gz: 5c77dbdbe0cccc56193727474e29adcbeae82f32
4
+ data.tar.gz: adf4183d1aaf55fbce1c65f40b920c01ea787e6e
5
5
  SHA512:
6
- metadata.gz: 5deb9e5b4ee608639dd5e99581dc4474738c754b98fbf69387001cd3726f3aff7e27f1b2297938ac0bcf4d248d4ef44073ab434eb0155eab836f8c6241fa928a
7
- data.tar.gz: b1fc3aafb6777a28339b843cfdb5f3c2bf36fe8a10d012e3b65ff5dc3ec13ccdceb0e508da00a464fa17e158d8854f15515a75f667c33dde9d4ce9fddc7ee68f
6
+ metadata.gz: 2f96dfc2fda4cee69e3cc9cfa3c0132a570e805a2cdff7fb6deec1f394531e839134a87a1fd16d83ef7c73db023b3e1c12fd8825d4de9f01ec3721935b9c6b60
7
+ data.tar.gz: 6ddb896c4c6320c9a4f0002f9389009726e477fc86c13c340832c9fb53a878acc21c0f6ef6f92c1a09771c240b51cf074b9b9167d56622429a5d21a022e68ca6
@@ -1,7 +1,12 @@
1
1
  module TableStructured
2
- def self.new array, headers: :top
3
- # TODO: headers_left should probably mean the ids of entries
4
- struct = Struct.new *array.first.map(&:to_s).map(&:to_sym).tap{ |_| fail "headers should be unique" if _.dup.uniq! }
5
- array.drop(1).map{ |_| struct.new *_ }
2
+ def self.new object, headers: :top # TODO: headers_left should probably mean the ids of entries
3
+ if object.respond_to? :css
4
+ # the xml object ignores the :headers arg for now
5
+ struct = Struct.new *object.at_css("thead").css("th").map(&:text).map(&:to_sym).tap{ |_| fail "headers should be unique" if _.uniq! }
6
+ object.css("tr").drop(1).map{ |_| struct.new *_.css("td") }
7
+ else
8
+ struct = Struct.new *object.first.map(&:to_s).map(&:to_sym).tap{ |_| fail "headers should be unique" if _.uniq! }
9
+ object.drop(1).map{ |_| struct.new *_ }
10
+ end
6
11
  end
7
12
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "tablestructured"
3
- spec.version = "0.1.0"
3
+ spec.version = "0.1.1"
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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tablestructured
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Maslov aka Nakilon