Class: Voyager::Holdings::Collection
- Inherits:
-
Object
- Object
- Voyager::Holdings::Collection
- Defined in:
- lib/holdings/collection.rb
Constant Summary collapse
- DEFAULT_OPAC_URL =
"http://vetiver.cc.columbia.edu:7014/vxws/GetHoldingsService"
Instance Attribute Summary collapse
-
#records ⇒ Object
readonly
Returns the value of attribute records.
-
#xml ⇒ Object
readonly
Returns the value of attribute xml.
Class Method Summary collapse
-
.new_from_opac(bibid, conn = nil, url = DEFAULT_OPAC_URL) ⇒ Object
Invoke GetHoldingsService.
Instance Method Summary collapse
-
#initialize(raw_xml) ⇒ Collection
constructor
Convert raw xml from GetHoldingsService to xml record object.
-
#to_hash(options = {}) ⇒ Object
Generate output hash from Record class instances.
Constructor Details
#initialize(raw_xml) ⇒ Collection
Convert raw xml from GetHoldingsService to xml record object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/holdings/collection.rb', line 15 def initialize(raw_xml) raise "Voyager::Holdings::Collection got nil/empty raw_xml" unless raw_xml # transform raw_xml String into Nokogiri XML Document xml = Nokogiri::XML(raw_xml) raise "Voyager::Holdings::Collection retrieved nil/invalid XML" unless xml and xml.root # transform raw_xml String into Nokogiri XML Document @xml = add_xml_namespaces(xml) parse_xml end |
Instance Attribute Details
#records ⇒ Object (readonly)
Returns the value of attribute records.
4 5 6 |
# File 'lib/holdings/collection.rb', line 4 def records @records end |
#xml ⇒ Object (readonly)
Returns the value of attribute xml.
4 5 6 |
# File 'lib/holdings/collection.rb', line 4 def xml @xml end |
Class Method Details
.new_from_opac(bibid, conn = nil, url = DEFAULT_OPAC_URL) ⇒ Object
Invoke GetHoldingsService
9 10 11 12 |
# File 'lib/holdings/collection.rb', line 9 def self.new_from_opac(bibid, conn = nil, url = DEFAULT_OPAC_URL) conn ||= Voyager::Connection.new Collection.new(conn.request(url, :bibId => bibid)) end |
Instance Method Details
#to_hash(options = {}) ⇒ Object
Generate output hash from Record class instances
28 29 30 31 32 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 59 60 61 62 63 |
# File 'lib/holdings/collection.rb', line 28 def to_hash( = {}) .reverse_merge!(:output_type => :raw, :content_type => :full, :message_type => :long_message) # :output_type --> :raw (default) | :condensed # # if :output_type == :condensed # :content_type --> :brief | :full (default) # :brief --> basic elements: currently location_name, call_number, overall location status, services # :full --> all elements # if :content_type == :full # :message_type --> :short_message | :long_message (default) # raise ":output_type not defined" unless [:output_type] == :raw || [:output_type] == :condensed raise ":content_type not defined" unless [:content_type] == :full || [:content_type] == :brief raise ":message_type not defined" unless [:message_type] == :long_message || [:message_type] == :short_message output = {} case [:output_type] when :raw output[:records] = @records.collect { |rec| rec.to_hash } when :condensed # convert @records into a holdings hash holdings = @records.collect { |rec| rec.to_hash } case [:content_type] when :full output[:condensed_holdings_full] = condense_holdings(holdings,) when :brief output[:condensed_holdings_brief] = condense_holdings(holdings,) end end output end |