Wynn Netherland changelog.com/posts

Prism - command line and Ruby library parser for Microformats

Prism from Mark Wunsch is a cool Ruby library and command line tool for parsing Microformats. It even supports vCard export:

twitter_contacts = Prism.find 'http://twitter.com/markwunsch', :hcard
me = twitter_contacts.first
#=> "Mark Wunsch"
#=> "Wunsch"
#=> "http://markwunsch.com/"
File.open('mark.vcf','w') {|f| f.write me.to_vcard }
## Add me to your address book!

Or if the command line is your bag:

$: prism --hcard http://markwunsch.com > ~/Desktop/me.vcf

or using STDIN and cURL:

$: curl http://markwunsch.com | prism --hcard > ~/Desktop/me.vcf

Prism also includes a DSL for parsing your own POSH formats:

class Navigation < Prism::POSH::Base
    search {|document| document.css('ul#navigation') }
    # Search a Nokogiri document for nodes of a certain type

    validate {|node| node.matches?('ul#navigation') }
    # Validate that a node is the right element we want

    has_many :items do
        search {|doc| doc.css('li') }
    # has_many and has_one define properties, which themselves inherit from
    # Prism::POSH::Base, so you can do :has_one, :has_many, :search, :extract, etc.

[Source on GitHub] [Docs] [Mark Wunsch on Twitter]


Sign in or Join to comment or subscribe

Player art
  0:00 / 0:00