Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
96 lines (83 sloc) 3.12 KB
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>HappyMapper by John Nunemaker</title>
<link rel="stylesheet" href="css/common.css" type="text/css" />
</head>
<body>
<div id="wrapper">
<div id="header">
<h1>HappyMapper</h1>
<p>XML to object mapping library.</p>
<ul id="nav">
<li><a href="http://rdoc.info/projects/jnunemaker/happymapper">Docs</a></li>
<li><a href="http://github.com/jnunemaker/happymapper">Github</a></li>
</ul>
</div>
<div id="content">
<h2>Install</h2>
<pre><code>$ gem install happymapper</code></pre>
<h2>Examples</h2>
<h3>Given the following xml:</h3>
<pre><code>&lt;statuses type="array">
&lt;status>
&lt;created_at>Sat Aug 09 05:38:12 +0000 2008&lt;/created_at>
&lt;id>882281424&lt;/id>
&lt;text>I so just thought the guy lighting the Olympic torch was falling when he began to run on the wall. Wow that would have been catastrophic.&lt;/text>
&lt;source>web&lt;/source>
&lt;truncated>false&lt;/truncated>
&lt;in_reply_to_status_id>1234&lt;/in_reply_to_status_id>
&lt;in_reply_to_user_id>12345&lt;/in_reply_to_user_id>
&lt;favorited>&lt;/favorited>
&lt;user>
&lt;id>4243&lt;/id>
&lt;name>John Nunemaker&lt;/name>
&lt;screen_name>jnunemaker&lt;/screen_name>
&lt;location>Mishawaka, IN, US&lt;/location>
&lt;description>Loves his wife, ruby, notre dame football and iu basketball&lt;/description>
&lt;profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/53781608/Photo_75_normal.jpg&lt;/profile_image_url>
&lt;url>http://addictedtonew.com&lt;/url>
&lt;protected>false&lt;/protected>
&lt;followers_count>486&lt;/followers_count>
&lt;/user>
&lt;/status>
&lt;/statuses></code></pre>
<h3>You could have the following objects:</h3>
<pre><code>class User
include HappyMapper
element :id, Integer
element :name, String
element :screen_name, String
element :location, String
element :description, String
element :profile_image_url, String
element :url, String
element :protected, Boolean
element :followers_count, Integer
end
class Status
include HappyMapper
element :id, Integer
element :text, String
element :created_at, Time
element :source, String
element :truncated, Boolean
element :in_reply_to_status_id, Integer
element :in_reply_to_user_id, Integer
element :favorited, Boolean
has_one :user, User
end
statuses = Status.parse(file_contents)
statuses.each do |status|
puts status.user.name, status.user.screen_name, status.text, status.source, ''
end</code></pre>
<h2>Support</h2>
<p>Conversations welcome in the <a href="http://groups.google.com/group/happymapper">google group</a> and bugs/features over at <a href="http://github.com/jnunemaker/happymapper/issues/">Github</a>.</p>
</div>
<div id="footer">
<p>Created by <a href="http://railstips.org/about/">John Nunemaker</a></p>
</div>
</div>
</body>
</html>
Something went wrong with that request. Please try again.