This is a simple ruby gem for parsing GreenButton data from either an XML file or an XML file loaded into a string.
Basically, this gem provides a convenient way to load and inspect GreenButton data. It will take care or normalizing energy usage to kWh and cost to USD by taking into account the multiplier and other related parameters specified in the provided XML.
You can use this library like this:
GreenButton::GreenButtonData.new("mydata.xml") do | entries |
entries.each |e|
puts e
end
endIf you prefer not to provide a block during initialization, you can always access loaded data like this:
data = GreenButton::GreenButtonData.new("mydata.xml")
data.each do |e|
puts e
endThe loaded data object and the entries there-in print information about loaded data:
# print sumary of loaded data-set
puts data
# prints something like:
# 2012-07-02 01:16:47 -0500 to: 2012-07-02 01:18:27 -0500, usage: 275.00kWh, cost: $550.00This is a more flexible way of accessing data since it allows simple Enumerable operations:
total_cost = data.reduce(0) { |sum, e| sum + e.cost }
all_costs = data.map { |e| e.cost }
# all_costs = [1.21, 2.32, 1.34 ...]This software is provided under the MIT license. Please read the accompanied LICENSE for more details.
This library is a work in progress and new features are being added constantly. Stay tuned!
This project has been sponsored by Interlink Network Systems. Thanks!
