chop 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +36 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/chop.gemspec +25 -0
- data/lib/chop.rb +9 -0
- data/lib/chop/builder.rb +76 -0
- data/lib/chop/definition_list.rb +51 -0
- data/lib/chop/table.rb +92 -0
- data/lib/chop/unordered_list.rb +51 -0
- data/lib/chop/version.rb +3 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 94a2a2f159e4a080262c2e468d7d9ce0cd47c581
|
4
|
+
data.tar.gz: ff743ac73daf8117ce661f9d54b13ae0505dfb2f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8d7ee5f0b4ebd55566dd3f307b4f3f96cf3fd6b0b71319a1a14915a2dafe4f907dfd6a33ede4f24523e3d0119611b80fa9e2b0e1e3f4f3ac9217472aeb067b1c
|
7
|
+
data.tar.gz: 40d30162f232c7b34cbfa4e4c0b2a4ea65b9d0964e4cb882532a2cea3898d6914b7296302d551fb8664ee09a8313bd65a0818fc5cdffed397dbfbfde62957e0e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Micah Geisel
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all 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,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Chop
|
2
|
+
|
3
|
+
Slice and dice your Cucumber tables with ease!
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
group :test do
|
9
|
+
gem 'chop'
|
10
|
+
end
|
11
|
+
```
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
TODO: Write more usage instructions here. See the source for usage in the meantime.
|
16
|
+
|
17
|
+
* `Chop::Builder`: Create ActiveRecord instances from a Cucumber table.
|
18
|
+
|
19
|
+
* `Chop::Table`: Diff a Cucumber table with a <table>.
|
20
|
+
* `Chop::DefinitionList`: Diff a Cucumber table with a <dl>.
|
21
|
+
* `Chop::UnorderedList`: Diff a Cucumber table with a <ul>.
|
22
|
+
|
23
|
+
## Development
|
24
|
+
|
25
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
26
|
+
|
27
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/botandrose/chop.
|
32
|
+
|
33
|
+
## License
|
34
|
+
|
35
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
36
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "chop"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/chop.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'chop/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "chop"
|
8
|
+
spec.version = Chop::VERSION
|
9
|
+
spec.authors = ["Micah Geisel"]
|
10
|
+
spec.email = ["micah@botandrose.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Slice and dice your cucumber tables with ease!}
|
13
|
+
spec.description = %q{Slice and dice your cucumber tables with ease!}
|
14
|
+
spec.homepage = "http://github.com/botandrose/chop"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
end
|
data/lib/chop.rb
ADDED
data/lib/chop/builder.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
module Chop
|
2
|
+
class Builder < Struct.new(:table, :klass, :block)
|
3
|
+
def self.build! table, klass, &block
|
4
|
+
new(table, klass, block).build!
|
5
|
+
end
|
6
|
+
|
7
|
+
attr_accessor :transformations
|
8
|
+
|
9
|
+
def initialize(*)
|
10
|
+
super
|
11
|
+
self.transformations = []
|
12
|
+
underscore_keys
|
13
|
+
instance_eval &block if block.respond_to?(:call)
|
14
|
+
end
|
15
|
+
|
16
|
+
def build!
|
17
|
+
table.hashes.map do |attributes|
|
18
|
+
transformations.each { |transformation| transformation.call(attributes) }
|
19
|
+
klass.create! attributes
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def transformation &block
|
24
|
+
transformations << block
|
25
|
+
end
|
26
|
+
|
27
|
+
def field attribute
|
28
|
+
transformation do |attributes|
|
29
|
+
attributes[attribute.to_s] = yield(attributes.fetch(attribute.to_s, ""))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def underscore_keys
|
34
|
+
transformation do |attributes|
|
35
|
+
new_attributes = attributes.inject({}) do |hash, (key, value)|
|
36
|
+
hash.merge key.parameterize.underscore => value
|
37
|
+
end
|
38
|
+
attributes.replace new_attributes
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def file *keys
|
43
|
+
keys.each do |key|
|
44
|
+
field key do |path|
|
45
|
+
File.open("features/support/fixtures/#{path}") if path.present?
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def files *keys
|
51
|
+
keys.each do |key|
|
52
|
+
field key do |paths|
|
53
|
+
paths.split(" ").map do |path|
|
54
|
+
File.open("features/support/fixtures/#{path}")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def has_many key, class_name=nil, delimiter: ", ", name_field: :name
|
61
|
+
field key do |names|
|
62
|
+
names.split(delimiter).map do |name|
|
63
|
+
class_name.find_by!(name_field => name)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def has_one key, class_name=nil, name_field: :name
|
69
|
+
field key do |name|
|
70
|
+
class_name.find_by!(name_field => name)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
alias_method :belongs_to, :has_one
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "delegate"
|
2
|
+
|
3
|
+
module Chop
|
4
|
+
class DefinitionList < SimpleDelegator
|
5
|
+
def self.diff! table, &block
|
6
|
+
new.diff! table
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize selector = "dl", session: Capybara.current_session
|
10
|
+
super(session)
|
11
|
+
@selector = selector
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_a
|
15
|
+
rows.collect do |row|
|
16
|
+
row_to_text(row)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def normalized_to_a
|
21
|
+
raw = to_a
|
22
|
+
max = raw.map(&:count).max
|
23
|
+
raw.select { |row| row.count == max }
|
24
|
+
end
|
25
|
+
|
26
|
+
def diff! table
|
27
|
+
table.diff! normalized_to_a
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def rows
|
33
|
+
node.all("dfn")
|
34
|
+
end
|
35
|
+
|
36
|
+
def node
|
37
|
+
@node ||= find(@selector)
|
38
|
+
end
|
39
|
+
|
40
|
+
def row_to_text row
|
41
|
+
row.all("dt,dd").collect do |cell|
|
42
|
+
text = cell.text
|
43
|
+
if text.blank? and image = cell.all("img").first
|
44
|
+
text = image["alt"]
|
45
|
+
end
|
46
|
+
text
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
data/lib/chop/table.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
require "delegate"
|
2
|
+
|
3
|
+
module Chop
|
4
|
+
class Table < SimpleDelegator
|
5
|
+
def self.diff! table, &block
|
6
|
+
klass = Class.new(self) do
|
7
|
+
class_attribute :cell_transformers
|
8
|
+
self.cell_transformers = []
|
9
|
+
|
10
|
+
def self.cell index, &block
|
11
|
+
cell_transformers[index] = block
|
12
|
+
end
|
13
|
+
|
14
|
+
def cell_to_text cell, index
|
15
|
+
if transformer = cell_transformers[index]
|
16
|
+
transformer.call cell
|
17
|
+
else
|
18
|
+
super
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
instance_eval &block if block_given?
|
23
|
+
end
|
24
|
+
|
25
|
+
klass.new.diff! table
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize selector = "table", session: Capybara.current_session
|
29
|
+
super(session)
|
30
|
+
@selector = selector
|
31
|
+
end
|
32
|
+
|
33
|
+
def header_elements
|
34
|
+
rows("thead")
|
35
|
+
end
|
36
|
+
|
37
|
+
def header
|
38
|
+
header_elements.collect do |row|
|
39
|
+
row.all(:xpath, "./*").map(&:text)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def body_elements
|
44
|
+
rows("tbody")
|
45
|
+
end
|
46
|
+
|
47
|
+
def body
|
48
|
+
body_elements.collect do |row|
|
49
|
+
row_to_text(row)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_a
|
54
|
+
header + body
|
55
|
+
end
|
56
|
+
|
57
|
+
def normalized_to_a
|
58
|
+
raw = to_a
|
59
|
+
max = raw.map(&:count).max
|
60
|
+
raw.select { |row| row.count == max }
|
61
|
+
end
|
62
|
+
|
63
|
+
def diff! table
|
64
|
+
table.diff! normalized_to_a
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def rows parent = nil
|
70
|
+
node.all("#{parent} tr")
|
71
|
+
end
|
72
|
+
|
73
|
+
def node
|
74
|
+
@node ||= find(@selector)
|
75
|
+
end
|
76
|
+
|
77
|
+
def row_to_text row
|
78
|
+
row.all(:xpath, "./*").map.with_index do |cell, index|
|
79
|
+
cell_to_text cell, index
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def cell_to_text cell, index
|
84
|
+
text = cell.text
|
85
|
+
if text.blank? and image = cell.all("img").first
|
86
|
+
text = image["alt"]
|
87
|
+
end
|
88
|
+
text
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "delegate"
|
2
|
+
|
3
|
+
module Chop
|
4
|
+
class UnorderedList < SimpleDelegator
|
5
|
+
def self.diff! table, &block
|
6
|
+
new.diff! table
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize selector = "ul", session: Capybara.current_session
|
10
|
+
super(session)
|
11
|
+
@selector = selector
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_a
|
15
|
+
rows.collect do |row|
|
16
|
+
row_to_text(row)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def normalized_to_a
|
21
|
+
raw = to_a
|
22
|
+
max = raw.map(&:count).max
|
23
|
+
raw.select { |row| row.count == max }
|
24
|
+
end
|
25
|
+
|
26
|
+
def diff! table
|
27
|
+
table.diff! normalized_to_a
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def rows
|
33
|
+
node.all("li")
|
34
|
+
end
|
35
|
+
|
36
|
+
def node
|
37
|
+
@node ||= find(@selector)
|
38
|
+
end
|
39
|
+
|
40
|
+
def row_to_text row
|
41
|
+
[row].collect do |cell|
|
42
|
+
text = cell.text
|
43
|
+
if text.blank? and image = cell.all("img").first
|
44
|
+
text = image["alt"]
|
45
|
+
end
|
46
|
+
text
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
data/lib/chop/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chop
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.7.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Micah Geisel
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
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
|
+
description: Slice and dice your cucumber tables with ease!
|
56
|
+
email:
|
57
|
+
- micah@botandrose.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- chop.gemspec
|
72
|
+
- lib/chop.rb
|
73
|
+
- lib/chop/builder.rb
|
74
|
+
- lib/chop/definition_list.rb
|
75
|
+
- lib/chop/table.rb
|
76
|
+
- lib/chop/unordered_list.rb
|
77
|
+
- lib/chop/version.rb
|
78
|
+
homepage: http://github.com/botandrose/chop
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.6.8
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: Slice and dice your cucumber tables with ease!
|
102
|
+
test_files: []
|