capybara-table 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY.md +10 -0
- data/README.md +2 -1
- data/lib/capybara-table/version.rb +1 -1
- data/lib/capybara-table.rb +26 -24
- metadata +1 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d3b3a786e6821358cbbe5bc270a7dfb09021413
|
4
|
+
data.tar.gz: 24750d8b5b1ac46eece388ea68f024190ef5cf82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ec37741ccba95a27826df7ee692d7afc8d7d9fc4b11230d393bd8d3e8e2e1babbe43499c6dd8ef36ab991d4f9e38d6a02c35ec0e1e535a63ee511baff87412b
|
7
|
+
data.tar.gz: ff860c65566f9bcce83a5cf9ffb2b18429331f42c3fe60b7929fe91f4ea42a9c292674d4ddb749c73d3411183262f078eb1107d3de7b30714bf12b5614e9df48
|
data/HISTORY.md
CHANGED
@@ -1,4 +1,14 @@
|
|
1
1
|
## Released Versions
|
2
|
+
### Version 0.0.2
|
3
|
+
#### Patch: Improvement to parsing and querying
|
4
|
+
##### Changed
|
5
|
+
* All data parsing and querying downcased
|
6
|
+
* Table parsing getting headers and body
|
7
|
+
* Data querying, more stable
|
8
|
+
|
9
|
+
##### Added
|
10
|
+
##### Fixed
|
11
|
+
|
2
12
|
### Version 0.0.1
|
3
13
|
#### Patch: Pre release inital code and testing
|
4
14
|
##### Changed
|
data/README.md
CHANGED
@@ -6,4 +6,5 @@ a table parser for capybara
|
|
6
6
|
[![Code Climate](https://codeclimate.com/github/benSlaughter/capybara-table.png)](https://codeclimate.com/github/benSlaughter/capybara-table)
|
7
7
|
[![Build Status](https://travis-ci.org/benSlaughter/capybara-table.png?branch=master)](https://travis-ci.org/benSlaughter/capybara-table)
|
8
8
|
[![Dependency Status](https://gemnasium.com/benSlaughter/capybara-table.png)](https://gemnasium.com/benSlaughter/capybara-table)
|
9
|
-
[![Coverage Status](https://coveralls.io/repos/benSlaughter/capybara-table/badge.png?branch=master)](https://coveralls.io/r/benSlaughter/capybara-table)
|
9
|
+
[![Coverage Status](https://coveralls.io/repos/benSlaughter/capybara-table/badge.png?branch=master)](https://coveralls.io/r/benSlaughter/capybara-table)
|
10
|
+
[![Gem Version](https://badge.fury.io/rb/capybara-table.png)](http://badge.fury.io/rb/capybara-table)
|
data/lib/capybara-table.rb
CHANGED
@@ -6,54 +6,56 @@ class Table
|
|
6
6
|
include Capybara::DSL
|
7
7
|
|
8
8
|
def initialize element = "table"
|
9
|
-
@element
|
10
|
-
|
9
|
+
@element = element
|
10
|
+
@headers = Hashie::Mash.new
|
11
|
+
@row_headers = Hashie::Mash.new
|
12
|
+
|
13
|
+
parse_body
|
11
14
|
parse_headers
|
12
|
-
|
15
|
+
parse_row_headers
|
13
16
|
end
|
14
17
|
|
15
|
-
def
|
16
|
-
@
|
18
|
+
def parse_body
|
19
|
+
@table_body = all("#{@element} > tbody > tr").map{ |h| h.all("td").map{| e| e.text.downcase } }
|
17
20
|
end
|
18
21
|
|
19
22
|
def parse_headers
|
20
|
-
@headers = Hashie::Mash.new
|
21
|
-
@header_rows = Hashie::Mash.new
|
22
23
|
all("table > thead > tr").map{ |h| h.all "th" }.each do | header_row |
|
23
|
-
|
24
|
-
header_row.
|
25
|
-
@headers[header.text] ||= []
|
24
|
+
column_index = 0
|
25
|
+
header_row.each do | header |
|
26
|
+
@headers[header.text.downcase] ||= []
|
26
27
|
(header["colspan"] ? header["colspan"].to_i : 1).times do
|
27
|
-
@headers[header.text].push
|
28
|
-
|
28
|
+
@headers[header.text.downcase].push column_index
|
29
|
+
|
30
|
+
column_index += 1
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
34
|
-
def
|
35
|
-
@row_headers =
|
36
|
-
all("#{@element} > tbody > tr").each_with_index{ |r,i| @row_headers[r.find("td:first-child").text] = i }
|
36
|
+
def parse_row_headers
|
37
|
+
all("#{@element} > tbody > tr").each_with_index{ |r,i| @row_headers[r.find("td:first-child").text.downcase] = i }
|
37
38
|
end
|
38
39
|
|
39
|
-
def
|
40
|
-
columns = columns.map{|c| @headers[c] }.inject(:&)
|
41
|
-
row = @row_headers[row]
|
40
|
+
def get_cells row, columns
|
41
|
+
columns = columns.map{|c| @headers[c.downcase] ? @headers[c.downcase] : [] }.inject(:&)
|
42
|
+
row = @row_headers[row.downcase]
|
42
43
|
|
43
44
|
temp = []
|
44
45
|
columns.each do |column_index|
|
45
|
-
temp.push @
|
46
|
+
temp.push @table_body[row][column_index]
|
46
47
|
end
|
47
48
|
|
48
|
-
temp
|
49
|
+
raise "Unable to find any matching data with row: %s and columns: %s" % [row, columns.to_s] if temp.empty?
|
50
|
+
temp.length == 1 ? temp.first : temp
|
49
51
|
end
|
50
52
|
|
51
53
|
def row number
|
52
|
-
@
|
54
|
+
@table_body[number]
|
53
55
|
end
|
54
56
|
|
55
57
|
def column number
|
56
|
-
@headers.inject([]) { |sum,h| h[1].include?(number) ? sum.push(h[0]) : sum} + @
|
58
|
+
@headers.inject([]) { |sum,h| h[1].include?(number) ? sum.push(h[0]) : sum} + @table_body.map {|r| r[number]}
|
57
59
|
end
|
58
60
|
|
59
61
|
def width
|
@@ -65,6 +67,6 @@ class Table
|
|
65
67
|
end
|
66
68
|
|
67
69
|
def [] number
|
68
|
-
@
|
70
|
+
@table_body.map {|r| r[number]}
|
69
71
|
end
|
70
|
-
end
|
72
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capybara-table
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Slaughter
|
@@ -66,20 +66,6 @@ dependencies:
|
|
66
66
|
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: coveralls
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - '>='
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - '>='
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: capybara
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|