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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 90162bee25d6b5138477a59ef716cc727774a2f0
4
- data.tar.gz: a47c3413091bd3c8e1d827b062dda6ca959c6231
3
+ metadata.gz: 7d3b3a786e6821358cbbe5bc270a7dfb09021413
4
+ data.tar.gz: 24750d8b5b1ac46eece388ea68f024190ef5cf82
5
5
  SHA512:
6
- metadata.gz: bce75b3a8f66145b68f2ab682b7214f71d9aef45aa3eb0a48d11244ef3f7799a61bffeb808180de63efdabf51a351d0601139a4c1750fe6bee73a184190ecbf7
7
- data.tar.gz: 70af08c81881929dd6ca7598b81898d277b12fade66b4bb47db9d4dede4bda2e25b294f8397f9c72a859d77bff1fdae73af04f985cdc9890f274bd510ebea04f
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)
@@ -1,6 +1,6 @@
1
1
  class Table
2
2
  # Current Allotment verion
3
- VERSION = "0.0.1".freeze
3
+ VERSION = "0.0.2".freeze
4
4
  # Date version created
5
5
  DATE = "2013-12-19".freeze
6
6
  end
@@ -6,54 +6,56 @@ class Table
6
6
  include Capybara::DSL
7
7
 
8
8
  def initialize element = "table"
9
- @element = element
10
- parse_table
9
+ @element = element
10
+ @headers = Hashie::Mash.new
11
+ @row_headers = Hashie::Mash.new
12
+
13
+ parse_body
11
14
  parse_headers
12
- parse_rows
15
+ parse_row_headers
13
16
  end
14
17
 
15
- def parse_table
16
- @table = all("#{@element} > tbody > tr").map{ |h| h.all("td").map{| e| e.text } }
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
- index = 0
24
- header_row.each_with_index do | header, index |
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 index
28
- index += 1
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 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 }
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 get_info row, columns
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 @table[row][column_index]
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
- @table[number]
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} + @table.map {|r| r[number]}
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
- @table.map {|r| r[number]}
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.1
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