File: current_weather.rb

package info (click to toggle)
ruby-roxml 4.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 800 kB
  • sloc: ruby: 4,133; xml: 1,013; makefile: 7
file content (27 lines) | stat: -rwxr-xr-x 833 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env ruby
require_relative './../spec/spec_helper'

class Base
  include ROXML
  xml_convention :dasherize
  xml_namespace 'aws'
end

class WeatherObservation < Base
  xml_name 'ob'
  xml_reader :temperature, :as => Float, :from => 'aws:temp'
  xml_reader :feels_like, :as => Integer
  xml_reader :current_condition #, :attributes => {:icon => String} # pending
end

class Weather < Base
  xml_reader :observation, :as => WeatherObservation, :required => true
end

unless defined?(RSpec)
  current_weather = Weather.from_xml(xml_for('current_weather')).observation
  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}"  # pending
end