diff --git a/Readme.md b/Readme.md index aef829e..32156cc 100644 --- a/Readme.md +++ b/Readme.md @@ -39,6 +39,9 @@ gb = GreenButton.load_xml_from_file('PATH/TO/FILE.XML') # To load from URL: gb = GreenButton.load_xml_from_web('https://services.greenbuttondata.org/DataCustodian/espi/1_1/resource/Batch/RetailCustomer/3/UsagePoint') + +# To load from string: +gb = GreenButton.load_xml_from_string(xml_string) ``` This code will load the Green Button XML from the given file or URL and parse it into a series of Ruby objects representing the data contained in the file. diff --git a/lib/greenbutton.rb b/lib/greenbutton.rb index 2ea8254..4ac4ffe 100644 --- a/lib/greenbutton.rb +++ b/lib/greenbutton.rb @@ -18,7 +18,12 @@ def self.load_xml_from_file(path) xml_file.remove_namespaces! Parser.new(xml_file) end - + + def self.load_xml_from_string(string) + xml_file = Nokogiri::XML.parse(string) + xml_file.remove_namespaces! + Parser.new(xml_file) + end class Parser attr_accessor :doc, :usage_points diff --git a/lib/greenbutton/gb_classes.rb b/lib/greenbutton/gb_classes.rb index edf10c4..b4c6d65 100644 --- a/lib/greenbutton/gb_classes.rb +++ b/lib/greenbutton/gb_classes.rb @@ -1,7 +1,6 @@ module GreenButtonClasses require_relative 'helpers.rb' require 'nokogiri' - require 'pry' Rule = Helper::Rule RULES = {