jnunemaker / happymapper

object to xml mapping library

This URL has Read+Write access

brandon (author)
Thu Jan 29 19:20:34 -0800 2009
jnunemaker (committer)
Thu Jan 29 20:11:43 -0800 2009
commit  4cf558a554a3e1205fcd94675d296cd1108ab7da
tree    13da5a3a2e3742770bd39426b82f43bfb243b92e
parent  1a23fbe9dd6e8d842737f9c0421c267ec46bb8ec
happymapper / examples / current_weather.rb
100644 21 lines (17 sloc) 0.774 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'happymapper')
 
file_contents = File.read(dir + '/../spec/fixtures/current_weather.xml')
 
class CurrentWeather
  include HappyMapper
  
  tag 'ob'
  namespace 'aws'
  element :temperature, Integer, :tag => 'temp'
  element :feels_like, Integer, :tag => 'feels-like'
  element :current_condition, String, :tag => 'current-condition', :attributes => {:icon => String}
end
 
CurrentWeather.parse(file_contents).each do |current_weather|
  puts "temperature: #{current_weather.temperature}"
  puts "feels_like: #{current_weather.feels_like}"
  puts "current_condition: #{current_weather.current_condition}"
  puts "current_condition.icon: #{current_weather.current_condition.icon}"
end