capybara-table 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/HISTORY.md +16 -0
- data/LICENSE +20 -0
- data/README.md +9 -0
- data/lib/capybara-table.rb +70 -0
- data/lib/capybara-table/version.rb +6 -0
- data/spec/fixtures/table.html +11 -0
- data/spec/helper.rb +10 -0
- data/spec/table_spec.rb +22 -0
- metadata +181 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 90162bee25d6b5138477a59ef716cc727774a2f0
|
4
|
+
data.tar.gz: a47c3413091bd3c8e1d827b062dda6ca959c6231
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bce75b3a8f66145b68f2ab682b7214f71d9aef45aa3eb0a48d11244ef3f7799a61bffeb808180de63efdabf51a351d0601139a4c1750fe6bee73a184190ecbf7
|
7
|
+
data.tar.gz: 70af08c81881929dd6ca7598b81898d277b12fade66b4bb47db9d4dede4bda2e25b294f8397f9c72a859d77bff1fdae73af04f985cdc9890f274bd510ebea04f
|
data/HISTORY.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
## Released Versions
|
2
|
+
### Version 0.0.1
|
3
|
+
#### Patch: Pre release inital code and testing
|
4
|
+
##### Changed
|
5
|
+
* Readme
|
6
|
+
|
7
|
+
##### Added
|
8
|
+
* First version of the table class
|
9
|
+
* Version file
|
10
|
+
* Spec files
|
11
|
+
* History and License
|
12
|
+
* Unit tests
|
13
|
+
* Gem files
|
14
|
+
* Travis files
|
15
|
+
|
16
|
+
##### Fixed
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Ben Slaughter
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
capybara-table
|
2
|
+
==============
|
3
|
+
|
4
|
+
a table parser for capybara
|
5
|
+
|
6
|
+
[![Code Climate](https://codeclimate.com/github/benSlaughter/capybara-table.png)](https://codeclimate.com/github/benSlaughter/capybara-table)
|
7
|
+
[![Build Status](https://travis-ci.org/benSlaughter/capybara-table.png?branch=master)](https://travis-ci.org/benSlaughter/capybara-table)
|
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)
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'hashie'
|
2
|
+
require 'capybara'
|
3
|
+
require 'capybara/dsl'
|
4
|
+
|
5
|
+
class Table
|
6
|
+
include Capybara::DSL
|
7
|
+
|
8
|
+
def initialize element = "table"
|
9
|
+
@element = element
|
10
|
+
parse_table
|
11
|
+
parse_headers
|
12
|
+
parse_rows
|
13
|
+
end
|
14
|
+
|
15
|
+
def parse_table
|
16
|
+
@table = all("#{@element} > tbody > tr").map{ |h| h.all("td").map{| e| e.text } }
|
17
|
+
end
|
18
|
+
|
19
|
+
def parse_headers
|
20
|
+
@headers = Hashie::Mash.new
|
21
|
+
@header_rows = Hashie::Mash.new
|
22
|
+
all("table > thead > tr").map{ |h| h.all "th" }.each do | header_row |
|
23
|
+
index = 0
|
24
|
+
header_row.each_with_index do | header, index |
|
25
|
+
@headers[header.text] ||= []
|
26
|
+
(header["colspan"] ? header["colspan"].to_i : 1).times do
|
27
|
+
@headers[header.text].push index
|
28
|
+
index += 1
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def parse_rows
|
35
|
+
@row_headers = Hashie::Mash.new
|
36
|
+
all("#{@element} > tbody > tr").each_with_index{ |r,i| @row_headers[r.find("td:first-child").text] = i }
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_info row, columns
|
40
|
+
columns = columns.map{|c| @headers[c] }.inject(:&)
|
41
|
+
row = @row_headers[row]
|
42
|
+
|
43
|
+
temp = []
|
44
|
+
columns.each do |column_index|
|
45
|
+
temp.push @table[row][column_index]
|
46
|
+
end
|
47
|
+
|
48
|
+
temp
|
49
|
+
end
|
50
|
+
|
51
|
+
def row number
|
52
|
+
@table[number]
|
53
|
+
end
|
54
|
+
|
55
|
+
def column number
|
56
|
+
@headers.inject([]) { |sum,h| h[1].include?(number) ? sum.push(h[0]) : sum} + @table.map {|r| r[number]}
|
57
|
+
end
|
58
|
+
|
59
|
+
def width
|
60
|
+
row(0).length
|
61
|
+
end
|
62
|
+
|
63
|
+
def height
|
64
|
+
column(0).length
|
65
|
+
end
|
66
|
+
|
67
|
+
def [] number
|
68
|
+
@table.map {|r| r[number]}
|
69
|
+
end
|
70
|
+
end
|
data/spec/helper.rb
ADDED
data/spec/table_spec.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
root = File.expand_path('..', __FILE__)
|
4
|
+
|
5
|
+
describe Table do
|
6
|
+
it "is a class" do
|
7
|
+
Table.class.should eq Class
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ".new" do
|
11
|
+
before(:all) do
|
12
|
+
Capybara.run_server = false
|
13
|
+
Capybara.default_driver = :selenium
|
14
|
+
Capybara.current_session.driver.visit "file://" + root + "/fixtures/table.html"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "creates a new table instance" do
|
18
|
+
t = Table.new
|
19
|
+
t.class.should eq Table
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capybara-table
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Slaughter
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: yard
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
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
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: capybara
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: selenium-webdriver
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: capybara
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: hashie
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: Parse and sort HTML table using Capybara, in a simple to use table object
|
140
|
+
email: b.p.slaughter@gmail.com
|
141
|
+
executables: []
|
142
|
+
extensions: []
|
143
|
+
extra_rdoc_files: []
|
144
|
+
files:
|
145
|
+
- README.md
|
146
|
+
- LICENSE
|
147
|
+
- HISTORY.md
|
148
|
+
- lib/capybara-table/version.rb
|
149
|
+
- lib/capybara-table.rb
|
150
|
+
- spec/fixtures/table.html
|
151
|
+
- spec/helper.rb
|
152
|
+
- spec/table_spec.rb
|
153
|
+
homepage: http://benslaughter.github.io/capybara-table/
|
154
|
+
licenses:
|
155
|
+
- MIT
|
156
|
+
metadata: {}
|
157
|
+
post_install_message:
|
158
|
+
rdoc_options: []
|
159
|
+
require_paths:
|
160
|
+
- lib
|
161
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - '>='
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
|
+
requirements:
|
168
|
+
- - '>='
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
171
|
+
requirements: []
|
172
|
+
rubyforge_project:
|
173
|
+
rubygems_version: 2.0.3
|
174
|
+
signing_key:
|
175
|
+
specification_version: 4
|
176
|
+
summary: HTML Table parsing for Capybara
|
177
|
+
test_files:
|
178
|
+
- spec/fixtures/table.html
|
179
|
+
- spec/helper.rb
|
180
|
+
- spec/table_spec.rb
|
181
|
+
has_rdoc:
|