New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

sawtooth

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sawtooth

  • 0.2.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source
                                                               __
                                                   _____....--' .'
                                      _..___...---'._ o      -`(
                       _             | |  _         \   .--.  `\
    ___  __ ___      _| |_ ___   ___ | |_| |__      |   \   \ `|
   / __|/ _` \ \ /\ / / __/ _ \ / _ \| __| '_ \     |o o |  |  |
   \__ \ (_| |\ V  V /| || (_) | (_) | |_| | | |     \___'.-`.  '.
   |___/\__,_| \_/\_/  \__\___/ \___/ \__|_| |_|          |   `---'
  '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^'

A companion for nokogori to parse XML files by rules, similar to Apache Commons Digester.

Converting XML structures into Ruby is most often an unsatisfying task, having to choose between implementing a SAX parser (for speed) or using nokogiri features like CSS selectors for ease of use. At it's base sawtooth is parsing documents using SAX, but provides an interface to specify rules for the handling the document.

require 'open-uri'
require 'sawtooth'

rules = Sawtooth.rules do
  before { |doc| doc << [] }                  # 1. create an array for all news items

  on 'rss/channel/item' do
    on_start  { |doc| doc << Hash.new }       # 2. on an item create hash
    on_finish { |doc| doc.parent << doc.pop } # 3. when closing an item, pop from stack and
  end                                         #    append to parent array (from step 1.)

  on_text 'rss/channel/item/*'                # 4. add contents to hash
end

result = rules.parse(open('http://rss.cnn.com/rss/edition.rss')).root
p result #=> [{ 'title' => 'Some CNN News...', 'guid' =>, ...}, ...]

This sample shows the DSL exposed to create the XML parsing rules for an RSS feed.

FAQs

Package last updated on 19 Jan 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc