#!/usr/bin/env ruby #should invoke this with (e.g.) ruby -Ilib example.rb in order to add lib/ to your search path require 'rubygems' #only if your libxml is installed under rubygems require 'eeml' require 'yaml' include Eeml #allows you to refer to Environment rather than Eeml::Environment #Example: make an environment from scratch env = Environment.new(:creator => 'http://www.example.com/ourstudio/', :feed_url => 'http://www.example.com/ourstudio/feeds/house.xml') env.title = 'my example feed' env.datastreams << DataStream.new(:value => 93.0, :identifier => 'room.1.humidity') env.datastreams << DataStream.new(:value => 91.0, :identifier => 'room.2.humidity') #Example: print out its eeml representation puts "Output as EEML" puts env.to_eeml #Example: print out its json representation puts "Output as JSON" puts env.to_json #Example: parse an environment from an eeml doc: puts "\nParsing an environment from a local eeml doc:" eeml_str = File.read('test/data/doc_1.xml') env2 = Environment.new_from_eeml(eeml_str) env2.datastreams.each do |ds| puts "ds %8s value is %6s (min:%8s, max:%8s)" %[ds.identifier, ds.value, ds.min_value, ds.max_value] end #TODO: Example: configure a different logger (to file; to stderr; different timestamp / format; use an existing rails logger)