Class: Voyager::Holdings::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/holdings/collection.rb

Constant Summary collapse

DEFAULT_OPAC_URL =
"http://sapote.cc.columbia.edu:7014/vxws/GetHoldingsService"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_xml) ⇒ Collection

Convert raw xml from GetHoldingsService to xml record object



15
16
17
18
# File 'lib/holdings/collection.rb', line 15

def initialize(raw_xml)
  @xml = load_and_namespace_xml(raw_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



21
22
23
24
25
26
27
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
# File 'lib/holdings/collection.rb', line 21

def to_hash(options = {})
  options.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 options[:output_type] == :raw || options[:output_type] == :condensed
  raise ":content_type not defined" unless options[:content_type] == :full || options[:content_type] == :brief
  raise ":message_type not defined" unless options[:message_type] == :long_message || options[:message_type] == :short_message
  
  output = {}

  case options[: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 options[:content_type]
    when :full
      output[:condensed_holdings_full] = condense_holdings(holdings,options)
    when :brief
      output[:condensed_holdings_brief] = condense_holdings(holdings,options)
    end
  end
    
  output

end