https://github.com/postmodern/nokogiri-ext
Useful extensions to nokogiri
https://github.com/postmodern/nokogiri-ext
extensions nokogiri ruby
Last synced: about 1 year ago
JSON representation
Useful extensions to nokogiri
- Host: GitHub
- URL: https://github.com/postmodern/nokogiri-ext
- Owner: postmodern
- License: mit
- Created: 2022-01-25T10:42:55.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-01-25T07:17:50.000Z (over 2 years ago)
- Last Synced: 2024-05-01T22:01:53.379Z (almost 2 years ago)
- Topics: extensions, nokogiri, ruby
- Language: Ruby
- Homepage:
- Size: 79.1 KB
- Stars: 7
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# nokogiri-ext
[](https://github.com/postmodern/nokogiri-ext/actions/workflows/ruby.yml)
[](https://badge.fury.io/rb/fake_io)
* [Source](https://github.com/postmodern/nokogiri-ext)
* [Issues](https://github.com/postmodern/nokogiri-ext/issues)
* [Documentation](http://rubydoc.info/gems/fake_io/frames)
## Description
nokogiri-ext is a collection of useful extensions to the [nokogiri] gem.
## Features
* Adds an `==` method to {Nokogiri::XML::Element}, {Nokogiri::XML::Attr},
{Nokogiri::XML::Text}, {Nokogiri::XML::Node}.
* Adds a `traverse_count` method to {Nokogiri::XML::Document} and
{Nokogiri::XML::Node}.
* Adds the {Nokogiri::XML::Node#traverse_text} method.
## Requirements
* [Ruby] >= 2.6.0
* [nokogiri] ~> 1.0
## Install
```shell
$ gem install nokogiri-ext
```
### gemspec
```ruby
gem.add_dependency 'nokogiri-ext', '~> 1.0'
```
### Gemfile
```ruby
gem 'nokogiri-ext', '~> 1.0'
```
## Examples
### equality
Compare the contents of two XML/HTML elements:
```ruby
require 'nokogiri/ext/equality'
doc1.at('//node') == doc2.at('//node')
```
Comparing the contents of two XML/HTML documents:
```ruby
doc1 == doc2
```
### traverse_count
Count the total number of elements under a XML/HTML element:
```ruby
require 'nokogiri/ext/traverse_count'
doc.at('//node').traverse_count
# => 7
```
Count the total number of elements within a XML/HTML document:
```ruby
doc.traverse_count
# => 42
```
### traverse_text
Traverses all text nodes in a XML/HTML document or node:
```ruby
require 'nokogiri/ext/traverse_text'
doc.traverse_text do |text|
puts text
end
```
## License
See {file:LICENSE.txt} for details.
[Ruby]: https://www.ruby-lang.org/
[nokogiri]: https://github.com/sparklemotion/nokogiri#readme