This post originated from an RSS feed registered with Ruby Buzz
by Gerald Bauer.
Original Post: Mofo - Getting Started w/ Microformats using Ruby - Web 3.0 In Action
Feed Title: Rails Advance - Workshop News
Feed URL: http://feeds.feedburner.com/railsadvance
Feed Description: Scott Patten and Gerald Bauer blog about Ruby on Rails topics covered in RailsAdvance workshops up in Vancouver, B.C. on Canada's Pacific West Coast in the Americas
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 Ruby on Rails Workshop on the Yahoo! Upcoming service using mofo – a microformat parser in Ruby .
Using 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.summary
Prints the events one-line summary:
=> Intermed. Ruby on Rails Workshop (Incl. Facebook and Mobile Web)
puts event.dtstart
Prints the event start date:
=> Fri Jan 25 00:00:00 -0800 2008
puts event.description
Prints the event description:
=> On Friday Jan 25, 2008, Scott Patten and Gerald Bauer (Rails Advance) are giving a full-day workshop on Intermediate Ruby on Rails at BCIT’s downtown campus. Sign-up and learn how to build a complete RESTful web application and web service using Rails 2.0 and then use ActiveResource to build a facebook and mobile application on top of the web service.
Using the pretty printer (pp) module we can print the hCard microformat inside the hCalendar microformat used to markup the event’s venue name and address:
Prints the event’s venue name and fn stands for full name:
=> BCIT Downtown Campus
puts event.location.adr.locality
Prints the event’s venue locality, that is, the city, village, or hamlet:
=> Vancouver
puts event.location.adr.street_address
Prints the event’s venue 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 event
That’s all to get started using Microformats in Ruby thanks to the mofo parser library.
Interested in learning more? Sign-up today for the world’s 1st Ruby on Rails workshop covering the Semantic Web, Web 3.0, Microformats and the Giant Global Graph.