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 .
event = hCalendar.find 'http://upcoming.yahoo.com/event/444250/'
hCalendar.findwe tell the mofo microformat parser to look for all events marked up in the web page using the
hCalendarmicroformat 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:
=> "Tue Apr 15 25 00:00:00 -0800 2008"Prints the 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."
hCardmicroformat inside the
hCalendarmicroformat 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:
'@properties=["locality", "street_address", "region", "postal_code"],'
'@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:
=> "Vancouver"Prints the event’s venue street address:
=> "555 Seymour Street"And so on and so forth. To see the fully monty pretty print the
hCalendarmicroformat and stand back 1000 meters:
pp eventThat’s all to get started using Microformats in Ruby thanks to the mofo parser library.