Skip to content

jwkvam/green-button-data

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Green Button Data

CI Results Gem Version Dependencies Code Coverage Code Climate

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

  1. Fork this project
  2. Create a feature branch: git checkout -b my-awesome-feature
  3. Make changes and commit: git commit -am "Add awesome feature"
  4. Push the branch: git push origin my-awesome-feature
  5. 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.

About

Fast Ruby parser for Green Button data XML document

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%