Green Button Data
Green Button Data is a Ruby gem that can quickly parse the Green Button data standard. It uses an event-driven SAX parser which does not build the entire DOM in memory.
Getting Started
Add the Green Button Data gem to your Gemfile:
gem 'green-button-data'
Then run Bundler:
$ bundle
Usage
Almost all of the functionality for parsing data is wrapped in the
GreenButtonData::Feed
class.
To parse a Green Button Atom feed, simply call the parse
method and pass in
the entire XML document:
require 'green-button-data'
xml_text = File.read "#{File.dirname __FILE__}/gb_example_interval_block.xml"
data = GreenButtonData::Feed.parse xml_text
You can then access the data like this:
# Print all the interval readings from the feed
data.entries.each do |entry|
p "Entry: #{entry.title}"
entry.content.interval_block.interval_readings.each do |reading|
time_period = reading.time_period
p "[#{time_period.starts_at} - #{time_period.ends_at}]: #{reading.value}"
end
end
Contributing
- Fork this project
- Create a feature branch:
git checkout -b my-awesome-feature
- Make changes and commit:
git commit -am "Add awesome feature"
- Push the branch:
git push origin my-awesome-feature
- Submit a pull request
License
This software is distributed AS IS WITHOUT WARRANTY under Simplified BSD license.
Verdigris Technologies Inc. assumes NO RESPONSIBILITY OR LIABILITY UNDER ANY CIRCUMSTANCES for usage of this software. See the LICENSE.txt file for detailed legal information.
Copyright © 2015, Verdigris Technologies Inc. All rights reserved.