nokogiri_bang_finders 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/.gitignore +17 -0
- data/.rspec +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/nokogiri_bang_finders/version.rb +3 -0
- data/lib/nokogiri_bang_finders.rb +25 -0
- data/nokogiri_bang_finders.gemspec +26 -0
- data/spec/nokogiri_bang_finders_spec.rb +97 -0
- data/spec/spec_helper.rb +15 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: e391b1470292d7057b9c4d2313b6bc76af79bb58
|
4
|
+
data.tar.gz: ed332b50ea2af4c6d09cfe158ae9756868cd2a0a
|
5
|
+
!binary "U0hBNTEy":
|
6
|
+
metadata.gz: 371837a464c03358e1145642a6517e5d27dc87eba1179633b957c988fb9096bb660922f03946fce5cb6ec9532dfeb63a8bf87818f0c50dd2d7482dae991f6986
|
7
|
+
data.tar.gz: 0f8ebbb89481f2e604d4584d9d7435954744828c911aeb49021532e94b34f4cda3ce3d66f9d6c81719c2b932245488fe398baced55b2078934b442309b17a1eb
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Nathan Long
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# nokogiri_bang_finders
|
2
|
+
|
3
|
+
This gem says "Nokogiri, if you can't find XML I want, yell about it."
|
4
|
+
|
5
|
+
Specifically, it adds the following methods:
|
6
|
+
|
7
|
+
- `at!`
|
8
|
+
- `at_xpath!`
|
9
|
+
- `at_css!`
|
10
|
+
|
11
|
+
...to `Nokogiri::XML::Node` and `Nokogiri::XML::NodeSet`.
|
12
|
+
|
13
|
+
Each method just calls its non-bang namesake and, if the result is `nil`, raises `Nokogiri::XML::NotFound`.
|
14
|
+
|
15
|
+
This gem is so tiny, you could just copy and paste its code. But if it's convenient, use it. :smile:
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
$ gem install nokogiri_bang_finders
|
20
|
+
|
21
|
+
... or via Bundler.
|
22
|
+
|
23
|
+
## Requiring
|
24
|
+
|
25
|
+
Be sure to `require 'nokogiri_bang_finders'` **after** you `require 'nokogiri'`. It expects `Nokogiri::XML::Node` and `Nokogiri::XML::NodeSet` to be defined so that it can add methods to them.
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
Use these methods just like you would use the normal Nokogiri versions, but expect an exception if the XML doesn't contain what you're looking for.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "nokogiri_bang_finders/version"
|
2
|
+
|
3
|
+
module Nokogiri
|
4
|
+
module XML
|
5
|
+
module BangFinders
|
6
|
+
def at!(*args)
|
7
|
+
at(*args).tap { |node| raise NotFound if node.nil? }
|
8
|
+
end
|
9
|
+
|
10
|
+
def at_xpath!(*args)
|
11
|
+
at_xpath(*args).tap { |node| raise NotFound if node.nil? }
|
12
|
+
end
|
13
|
+
|
14
|
+
def at_css!(*args)
|
15
|
+
at_css(*args).tap { |node| raise NotFound if node.nil? }
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
NotFound = Class.new(StandardError)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
Nokogiri::XML::Node.send(:include, Nokogiri::XML::BangFinders)
|
25
|
+
Nokogiri::XML::NodeSet.send(:include, Nokogiri::XML::BangFinders)
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'nokogiri_bang_finders/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "nokogiri_bang_finders"
|
8
|
+
spec.version = NokogiriBangFinders::VERSION
|
9
|
+
spec.authors = ["Nathan Long"]
|
10
|
+
spec.email = ["nathanmlong@gmail.com"]
|
11
|
+
spec.summary = %q{Adds XML finders to Nokogiri that raise if nothing is found.}
|
12
|
+
spec.description = %q{Adds XML finders to Nokogiri that raise if nothing is found.}
|
13
|
+
spec.homepage = "https://github.com/nathanl/nokogiri_bang_finders"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "nokogiri", ">= 1.0"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
24
|
+
spec.add_development_dependency "rspec", '~> 2.14.1'
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Nokogiri::XML::BangFinders do
|
4
|
+
|
5
|
+
let(:xml_doc) {
|
6
|
+
Nokogiri::XML("<root><aliens><alien><name>Alf</name></alien></aliens></root>")
|
7
|
+
}
|
8
|
+
let(:aliens_node) { xml_doc.at('aliens') }
|
9
|
+
|
10
|
+
describe "#at!" do
|
11
|
+
|
12
|
+
it "calls #at" do
|
13
|
+
expect(xml_doc).to receive('at').with('aliens').and_call_original
|
14
|
+
xml_doc.at!('aliens')
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "when #at returns something" do
|
18
|
+
|
19
|
+
it "returns it" do
|
20
|
+
expect(xml_doc.at!('aliens')).to eq(aliens_node)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "when #at returns nil" do
|
26
|
+
|
27
|
+
before :each do
|
28
|
+
expect(xml_doc).to receive('at').with('aliens').and_return(nil)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "raises an exception" do
|
32
|
+
expect{xml_doc.at!('aliens')}.to raise_error(Nokogiri::XML::NotFound)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#at_css!" do
|
40
|
+
|
41
|
+
it "calls #at" do
|
42
|
+
expect(xml_doc).to receive('at_css').with('aliens').and_call_original
|
43
|
+
xml_doc.at_css!('aliens')
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "when #at_css returns something" do
|
47
|
+
|
48
|
+
it "returns it" do
|
49
|
+
expect(xml_doc.at_css!('aliens')).to eq(aliens_node)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "when #at_css returns nil" do
|
55
|
+
|
56
|
+
before :each do
|
57
|
+
expect(xml_doc).to receive('at_css').with('aliens').and_return(nil)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "raises an exception" do
|
61
|
+
expect{xml_doc.at_css!('aliens')}.to raise_error(Nokogiri::XML::NotFound)
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#at_xpath!" do
|
69
|
+
|
70
|
+
it "calls #at" do
|
71
|
+
expect(xml_doc).to receive('at_xpath').with('//aliens').and_call_original
|
72
|
+
xml_doc.at_xpath!('//aliens')
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "when #at_xpath returns something" do
|
76
|
+
|
77
|
+
it "returns it" do
|
78
|
+
expect(xml_doc.at_xpath!('//aliens')).to eq(aliens_node)
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "when #at_xpath returns nil" do
|
84
|
+
|
85
|
+
before :each do
|
86
|
+
expect(xml_doc).to receive('at_xpath').with('//aliens').and_return(nil)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "raises an exception" do
|
90
|
+
expect{xml_doc.at_xpath!('//aliens')}.to raise_error(Nokogiri::XML::NotFound)
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'nokogiri_bang_finders'
|
3
|
+
|
4
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
7
|
+
config.run_all_when_everything_filtered = true
|
8
|
+
config.filter_run :focus
|
9
|
+
|
10
|
+
# Run specs in random order to surface order dependencies. If you find an
|
11
|
+
# order dependency and want to debug it, you can fix the order by providing
|
12
|
+
# the seed, which is printed after each run.
|
13
|
+
# --seed 1234
|
14
|
+
config.order = 'random'
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nokogiri_bang_finders
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nathan Long
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.14.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.14.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
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
|
+
description: Adds XML finders to Nokogiri that raise if nothing is found.
|
70
|
+
email:
|
71
|
+
- nathanmlong@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .rspec
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- lib/nokogiri_bang_finders.rb
|
83
|
+
- lib/nokogiri_bang_finders/version.rb
|
84
|
+
- nokogiri_bang_finders.gemspec
|
85
|
+
- spec/nokogiri_bang_finders_spec.rb
|
86
|
+
- spec/spec_helper.rb
|
87
|
+
homepage: https://github.com/nathanl/nokogiri_bang_finders
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.0.14
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Adds XML finders to Nokogiri that raise if nothing is found.
|
111
|
+
test_files:
|
112
|
+
- spec/nokogiri_bang_finders_spec.rb
|
113
|
+
- spec/spec_helper.rb
|