Class: OAI::Provider::Response::ListMetadataFormats

Inherits:
RecordResponse show all
Defined in:
lib/oai/provider/response/list_metadata_formats.rb

Instance Attribute Summary

Attributes inherited from Base

#options, #provider

Instance Method Summary collapse

Methods inherited from RecordResponse

#about_for, #data_for, #header_for, inherited

Methods inherited from Base

default_parameters, #initialize, required_parameters, #response, valid_parameters

Constructor Details

This class inherits a constructor from OAI::Provider::Response::Base

Instance Method Details

#record_supports(record, prefix) ⇒ Object



32
33
34
35
36
# File 'lib/oai/provider/response/list_metadata_formats.rb', line 32

def record_supports(record, prefix)
  prefix == 'oai_dc' or 
  record.respond_to?("to_#{prefix}") or
  record.respond_to?("map_#{prefix}")
end

#to_xmlObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/oai/provider/response/list_metadata_formats.rb', line 5

def to_xml
  # Get a list of all the formats the provider understands.
  formats = provider.formats.values
  
  # if it's a doc-specific request
  if options.include?(:identifier)
    id = extract_identifier(options[:identifier])
    unless record = provider.model.find(id, options)
      raise OAI::IdException.new
    end
  
    # Remove any format that this particular record can't be provided in.
    formats.reject! { |f| !record_supports(record, f.prefix) }
  end
  response do |r|
    r.ListMetadataFormats do
      formats.each do |format|
        r.metadataFormat do 
          r.metadataPrefix format.prefix
          r.schema format.schema
          r.metadataNamespace format.namespace
        end
      end
    end
  end
end