Class: Exlibris::Primo::Record
- Inherits:
-
Object
- Object
- Exlibris::Primo::Record
- Defined in:
- lib/exlibris/primo/record.rb
Overview
Overview
Exlibris::Primo::Record is an abstract representation of a Primo record. An instance of Exlibris::Primo::Record can be created by passing in a hash with setup parameters. Valid parameters include:
:base_url, :resolver_base_url, :vid, :institution, :record_id, :record
A URL to the native record (dlDisplay.do) and an OpenUrl are generated by default. If no resolver_base_url is provided, an OpenUrl querystring will be returned. A raw_xml attribute is generated either by the record XML passed in or by fetching it from the record_id. By default the raw_xml is not included in the hash representation, but can be overridden to.
Tips on Extending
When extending the class, a few basics guidelines should be observed.
-
A Exlibris::Primo::Record is initialized from a Hash of parameters. These params are used to create instance variables of the record attributes.
-
The following methods are available for overriding: to_h - if a sub class creates more instance variables, these should be added to the hash 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") })
Constant Summary collapse
- SEAR_NS =
{'sear' => 'http://www.exlibrisgroup.com/xsd/jaguar/search'}
Instance Attribute Summary collapse
-
#creator ⇒ Object
readonly
Returns the value of attribute creator.
-
#openurl ⇒ Object
readonly
Returns the value of attribute openurl.
-
#raw_xml ⇒ Object
readonly
Returns the value of attribute raw_xml.
-
#record_id ⇒ Object
readonly
Returns the value of attribute record_id.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(parameters = {}) ⇒ Record
constructor
A new instance of Record.
-
#raw(record) ⇒ Object
Method for cleaning up raw xml from record.
-
#to_h ⇒ Object
Return a hash representation of the primary record attributes.
-
#to_json ⇒ Object
Return a JSON representation of the PNX record.
Constructor Details
#initialize(parameters = {}) ⇒ Record
Returns a new instance of Record.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/exlibris/primo/record.rb', line 33 def initialize(parameters={}) # Get base url of Primo application, required base_url = parameters[:base_url] raise_required_setup_parameter_error :base_url if base_url.nil? # Get base url of link resolver, if blank openurl generates just querystring resolver_base_url = parameters[:resolver_base_url] # Get vid from parameters, required vid = parameters.fetch(:vid, "DEFAULT") raise_required_setup_parameter_error :vid if vid.nil? # Get institution from parameters, required institution = parameters.fetch(:institution, "PRIMO") raise_required_setup_parameter_error :institution if institution.nil? # Get record: either fetch record from Web Service based on DocId or use passed in record xml, required record = (parameters[:record].nil?) ? (parameters[:record_id].nil?) ? nil : record_from_id(parameters.delete(:record_id), base_url, {:institution => institution, :vid => vid}) : parameters.delete(:record) raise_required_setup_parameter_error "record or record_id" if record.nil? # Set instance variables for record @record_id = record.at("control/recordid",record.namespaces).inner_text unless record.at("control/recordid",record.namespaces).nil? @type = record.at("display/type",record.namespaces).inner_text unless record.at("display/type",record.namespaces).nil? @title = record.at("display/title",record.namespaces).inner_text unless record.at("display/title",record.namespaces).nil? @url = construct_url(base_url, @record_id, institution, vid) @openurl = construct_openurl(resolver_base_url, record, @record_id) @creator = record.at("display/creator",record.namespaces).inner_text unless record.at("display/creator",record.namespaces).nil? @raw_xml = raw(record) end |
Instance Attribute Details
#creator ⇒ Object (readonly)
Returns the value of attribute creator.
31 32 33 |
# File 'lib/exlibris/primo/record.rb', line 31 def creator @creator end |
#openurl ⇒ Object (readonly)
Returns the value of attribute openurl.
31 32 33 |
# File 'lib/exlibris/primo/record.rb', line 31 def openurl @openurl end |
#raw_xml ⇒ Object (readonly)
Returns the value of attribute raw_xml.
31 32 33 |
# File 'lib/exlibris/primo/record.rb', line 31 def raw_xml @raw_xml end |
#record_id ⇒ Object (readonly)
Returns the value of attribute record_id.
31 32 33 |
# File 'lib/exlibris/primo/record.rb', line 31 def record_id @record_id end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
31 32 33 |
# File 'lib/exlibris/primo/record.rb', line 31 def title @title end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
31 32 33 |
# File 'lib/exlibris/primo/record.rb', line 31 def type @type end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
31 32 33 |
# File 'lib/exlibris/primo/record.rb', line 31 def url @url end |
Instance Method Details
#raw(record) ⇒ Object
Method for cleaning up raw xml from record
78 79 80 |
# File 'lib/exlibris/primo/record.rb', line 78 def raw(record) record.to_xml(:indent => 0, :encoding => 'UTF-8') end |
#to_h ⇒ Object
Return a hash representation of the primary record attributes
61 62 63 64 65 66 67 68 69 |
# File 'lib/exlibris/primo/record.rb', line 61 def to_h return { "format" => @type.capitalize, "title" => @title, "author" => @creator, "url" => @url, "openurl" => @openurl } end |
#to_json ⇒ Object
Return a JSON representation of the PNX record
72 73 74 75 |
# File 'lib/exlibris/primo/record.rb', line 72 def to_json # Leverage ActiveSupport's Hash#from_xml method to transform PNX to JSON. Hash.from_xml(raw_xml).to_json end |