lib/exlibris/primo/record.rb in exlibris-primo-0.1.1 vs lib/exlibris/primo/record.rb in exlibris-primo-0.1.4
- old
+ new
@@ -21,11 +21,14 @@
# raw - cleans up characters and spaces in raw record and wraps in <record /> tag, implementations may differ
#
# == Examples of usage
# Record.new({ :base_url => @base_url, :vid => @vid, :record => doc.at("//record") })
class Record
-
+ # Leverage ActiveSupport's Hash#from_xml method to transform PNX to JSON.
+ require 'active_support/core_ext'
+ require 'json'
+
SEAR_NS = {'sear' => 'http://www.exlibrisgroup.com/xsd/jaguar/search'}
attr_reader :record_id, :type, :title, :url, :openurl, :creator, :raw_xml
def initialize(parameters={})
# Get base url of Primo application, required
@@ -63,16 +66,18 @@
"url" => @url,
"openurl" => @openurl
}
end
+ # Return a JSON representation of the PNX record
+ def to_json
+ # Leverage ActiveSupport's Hash#from_xml method to transform PNX to JSON.
+ Hash.from_xml(raw_xml).to_json
+ end
+
# Method for cleaning up raw xml from record
def raw(record)
- raw = "<record>"
- # Hack to strip out spacing in record
- record.children.each{|child| raw << child.to_xml.gsub(/\n\s*/, "").gsub(/\s$/, "")}
- raw << "</record>"
- return raw
+ record.to_xml(:indent => 0, :encoding => 'UTF-8')
end
private
# Method for consturcting openurl from record
def construct_openurl(resolver_base_url, record, record_id)
\ No newline at end of file