Skip to content

Commit 12f1a92

Browse files
committed
add OAI Record <about /> block
1 parent d56e675 commit 12f1a92

File tree

7 files changed

+38
-3
lines changed

7 files changed

+38
-3
lines changed

lib/oai/client/record.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ module OAI
1010

1111
class Record
1212
include OAI::XPath
13-
attr_accessor :header, :metadata
13+
attr_accessor :header, :metadata, :about
1414

1515
def initialize(element)
1616
@header = OAI::Header.new xpath_first(element, './/header')
1717
@metadata = xpath_first(element, './/metadata')
18+
@about = xpath_first(element, './/about')
1819
end
1920

2021
# a convenience method which digs into the header status attribute

lib/oai/provider/model.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ module OAI::Provider
1717
# available_formats - if overridden, individual records should return an
1818
# array of prefixes for all formats in which that record is available,
1919
# if other than ["oai_dc"]
20+
# about - if overridden, should return a String or Array of XML Strings to
21+
# insert into the OAI Record <about> chunks.
2022
#
2123
# == Resumption Tokens
2224
#
@@ -68,7 +70,11 @@ def find(selector, options={})
6870
def deleted?
6971
false
7072
end
71-
73+
74+
# can return a String or Array of XML Strings add as OAI Record <about> chunks.
75+
def about record
76+
nil
77+
end
7278
end
7379

7480
end

lib/oai/provider/response/get_record.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def to_xml
1414
r.record do
1515
header_for record
1616
data_for record unless deleted?(record)
17+
about_for record unless deleted?(record)
1718
end
1819
end
1920
end
@@ -23,4 +24,4 @@ def to_xml
2324

2425
end
2526

26-
27+

lib/oai/provider/response/list_records.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def to_xml
1515
r.record do
1616
header_for rec
1717
data_for rec unless deleted?(rec)
18+
about_for rec unless deleted?(rec)
1819
end
1920
end
2021

lib/oai/provider/response/record_response.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,21 @@ def data_for(record)
2626
@builder.target! << provider.format(requested_format).encode(provider.model, record)
2727
end
2828
end
29+
30+
# about - core routine for delivering about records
31+
#
32+
def about_for(record)
33+
return unless provider.model.respond_to? :about
34+
35+
about = provider.model.about(record)
36+
return if about.nil?
37+
38+
Array(about).each do |a|
39+
@builder.about do
40+
@builder.target! << a
41+
end
42+
end
43+
end
2944

3045
private
3146

test/client/tc_get_record.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ def test_get_one
99
assert_kind_of OAI::Record, response.record
1010
assert_kind_of REXML::Element, response.record.metadata
1111
assert_kind_of OAI::Header, response.record.header
12+
assert_kind_of REXML::Element, response.record.about
1213

1314
# minimal check that the header is working
1415
assert_equal 'oai:test/3',
1516
response.record.header.identifier
1617

1718
# minimal check that the metadata is working
1819
#assert 'en', response.record.metadata.elements['.//dc:language'].text
20+
assert_equal 'Ruby OAI test data', response.record.about.elements['.//dc:publisher'].text
1921
end
2022

2123
def test_missing_identifier

test/provider/models.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,5 +231,14 @@ def initialize(limit = nil)
231231
generate_records(250, Time.parse("December 25 2005"), [set_four, set_three_four])
232232
end
233233

234+
def about record
235+
<<-eos
236+
<oai_dc:dc
237+
xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"
238+
xmlns:dc="http://purl.org/dc/elements/1.1/">
239+
<dc:publisher>Ruby OAI test data</dc:publisher>
240+
</oai_dc:dc>
241+
eos
242+
end
234243
end
235244

0 commit comments

Comments
 (0)