The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Mofo - Getting Started w/ Microformats using Ruby - Web 3.0 In Action

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Gerald Bauer

Posts: 444
Nickname: gerald2007
Registered: Jul, 2007

Gerald Bauer is a Rails & Internet Professional in Vancouver B.C.
Mofo - Getting Started w/ Microformats using Ruby - Web 3.0 In Action Posted: Jan 17, 2008 7:47 PM
Reply to this message Reply

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
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Gerald Bauer
Latest Posts From Rails Advance - Workshop News

Advertisement

(This is cross-posted from Gerald Bauer’s Ruby Notebook .)

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 .

require 'mofo' 
require 'pp'

event = hCalendar.find 'http://upcoming.yahoo.com/event/390146/'

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:

pp event.location

Pretty prints the hCard microformat data:

#<HCard:0x5225a88
 @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"]>

We can, of course, print the items one at a time:

puts event.location.fn

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.

Read: Mofo - Getting Started w/ Microformats using Ruby - Web 3.0 In Action

Topic: Rubinius' Foreign Function Interface Previous Topic   Next Topic Topic: ZenTest &Uuml;berness

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use