Class: OAI::Provider::Response::RecordResponse

Inherits:
Base
  • Object
show all
Defined in:
lib/oai/provider/response/record_response.rb

Instance Attribute Summary

Attributes inherited from Base

#options, #provider

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

default_parameters, #initialize, required_parameters, #response, valid_parameters

Constructor Details

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

Class Method Details

.default_from(response) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/oai/provider/response/record_response.rb', line 10

def self.default_from(response)
  value = Time.parse(response.provider.model.earliest.to_s).utc
  if response.options[:until]
    u = parse_date(response.options[:until])
    value = value.to_date if u.is_a? Date
  end
  value
end

.default_until(response) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/oai/provider/response/record_response.rb', line 19

def self.default_until(response)
  value = Time.parse(response.provider.model.latest.to_s).utc
  if response.options[:from]
    f = parse_date(response.options[:from])
    value = value.to_date if f.is_a? Date
  end
  value
end

.inherited(klass) ⇒ Object



3
4
5
6
7
8
# File 'lib/oai/provider/response/record_response.rb', line 3

def self.inherited(klass)
  klass.valid_parameters    :metadata_prefix, :from, :until, :set
  klass.default_parameters  :metadata_prefix => "oai_dc",
       :from => method(:default_from).to_proc,
       :until => method(:default_until).to_proc
end

Instance Method Details

#about_for(record) ⇒ Object

about - core routine for delivering about records



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/oai/provider/response/record_response.rb', line 50

def about_for(record)
  return unless provider.model.respond_to? :about

  about = provider.model.about(record)
  return if about.nil?

  unless about.is_a? Array
    about = [about]
  end

  about.each do |a|
    @builder.about do
      @builder.target! << a
    end
  end
end

#data_for(record) ⇒ Object

metadata - core routine for delivering metadata records



42
43
44
45
46
# File 'lib/oai/provider/response/record_response.rb', line 42

def data_for(record)
  @builder. do
    @builder.target! << provider.format(requested_format).encode(provider.model, record)
  end
end

#header_for(record) ⇒ Object

emit record header



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/oai/provider/response/record_response.rb', line 29

def header_for(record)
  param = Hash.new
  param[:status] = 'deleted' if deleted?(record)
  @builder.header param do
    @builder.identifier identifier_for(record)
    @builder.datestamp timestamp_for(record)
    sets_for(record).each do |set|
      @builder.setSpec set.spec
    end
  end
end