Mofo - Getting Started w/ Microformats using Ruby - Web 3.0 In Action
What are Microformats? Microformats let you turn your web page into a web service using nothing more than simple coding conventions and patterns that work in today's browsers. If you markup events, people, reviews, locations and more in your web page using Microformats you contribute to the next version of the web – known as the Semantic Web, Web 3.0 or the Giant Global Graph (GGG).
Let's skip the theory and dive into code and tap into the Giant Global Graph.
Let's load up the event listing web page for the " SocialCamp Vancouver (Incl. Facebook Developer Garage) - Open Web Edition" on the Yahoo! Upcoming service using mofo – a microformat parser in Ruby .
require 'mofo'Using
require 'pp'
event = hCalendar.find 'http://upcoming.yahoo.com/event/444250/'
hCalendar.find we tell the mofo microformat parser to look for all events marked up in the web page using the hCalendar microformat standard.
That’s all. Now we’re ready to play with the event data:
puts event.summaryPrints the events one-line summary:
=> "SocialCamp Vancouver (Incl. Facebook Developer Garage) - Open Web Edition"Prints the event start date:
puts event.dtstart
=> "Tue Apr 15 25 00:00:00 -0800 2008"Prints the event description:
puts event.description
=> "We're back. Join us for Vancouver's 3rd Facebook Developer Garage and 1st"Using the pretty printer (pp) module we can print the
"(Open)Social(Web)Camp hosted at the Open Web Vancouver 2008 Conference on Day 2. "
"Please note, to attend you will need an Open Web Vancouver 2008 ticket."
"We have a SocialCampVancouver event wiki. Tell us about your Facebook or social network"
"web app and sign-up for a live demo and Q&A or sign-up for a lightning talk."
hCard microformat inside the hCalendar microformat used to markup the event’s venue name and address:
pp event.locationPretty prints the hCard microformat data:
'#<HCard:0x5225a88'We can, of course, print the items one at a time:
'@adr='
'#<Adr:0x5249d70'
'@locality="Vancouver",'
'@postal_code="",'
'@properties=["locality", "street_address", "region", "postal_code"],'
'@region="British Columbia",'
'@street_address="555 Seymour Street">,'
'@fn="BCIT Downtown Campus",'
'@org="BCIT Downtown Campus",'
'@properties=["fn", "adr", "org"]>'
puts event.location.fnPrints the event’s venue name and fn stands for full name:
=> "BCIT Downtown Campus"Prints the event’s venue locality, that is, the city, village, or hamlet:
puts event.location.adr.locality
=> "Vancouver"Prints the event’s venue street address:
puts event.location.adr.street_address
=> "555 Seymour Street"And so on and so forth. To see the fully monty pretty print the
hCalendar microformat and stand back 1000 meters:
pp eventThat’s all to get started using Microformats in Ruby thanks to the mofo parser library.
Reference:
- Login or register to post comments
- 201 reads
- Flag as offensive
- Printer-friendly version






