Skip to content

Commit 5453723

Browse files
committed
Replacing RDoc with YARD.
YARD is more flexible, and makes better looking documentation by default. Some updates to the documentation have also been made, including the use of seamless resumption.
1 parent 039ddf8 commit 5453723

File tree

14 files changed

+273
-226
lines changed

14 files changed

+273
-226
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/pkg/
22
/doc/
33
/coverage*
4+
/.yardoc/
45

56
# Exclude Gemfile.lock (best practice for gems)
67
Gemfile.lock

.yardopts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-m markdown

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ group :test do
99
gem 'activerecord-jdbcsqlite3-adapter', :platform => [:jruby]
1010
gem 'libxml-ruby', :platform => [:ruby, :mswin]
1111
gem 'rake'
12-
gem 'rdoc'
12+
gem 'yard'
13+
gem 'redcarpet' # For Markdown
1314
gem 'rcov', '~> 0.9', :platform => [:ruby_18, :jruby]
1415
gem 'simplecov', :platform => :ruby_19
1516
gem 'simplecov-rcov', :platform => :ruby_19

README.md

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ ruby-oai
22
========
33

44
ruby-oai is a Open Archives Protocol for Metadata Harvesting (OAI-PMH)
5-
library for Ruby. OAI-PMH[http://openarchives.org] it is a somewhat
5+
library for Ruby. [OAI-PMH](http://openarchives.org) is a somewhat
66
archaic protocol for sharing metadata between digital library repositories.
77
If you are looking to share metadata on the web you are probably better off
8-
using a feed format like RSS or Atom. If have to work with a backwards
8+
using a feed format like [RSS](http://www.rssboard.org/rss-specification) or
9+
[Atom](http://www.atomenabled.org/). If have to work with a backwards
910
digital repository that only offers OAI-PMH access then ruby-oai is your
1011
friend.
1112

12-
The [OAI-PMH](http://openarchives.org) spec defines six verbs (Identify, ListIdentifiers, ListRecords,
13-
GetRecords, ListSets, ListMetadataFormat) used for discovery and sharing of
13+
The [OAI-PMH](http://openarchives.org) spec defines six verbs
14+
(`Identify`, `ListIdentifiers`, `ListRecords`,
15+
`GetRecords`, `ListSets`, `ListMetadataFormat`) used for discovery and sharing of
1416
metadata.
1517

1618
The ruby-oai gem includes a client library, a server/provider library and
@@ -25,12 +27,23 @@ For example to initiate a ListRecords request to pubmed you can:
2527
```ruby
2628
require 'oai'
2729
client = OAI::Client.new 'http://www.pubmedcentral.gov/oai/oai.cgi'
28-
for record in client.list_records
30+
response = client.list_records
31+
# Get the first page of records
32+
response.each do |record|
33+
puts record.metadata
34+
end
35+
# Get the second page of records
36+
response = client.list_records(:resumption_token => response.resumption_token)
37+
response.each do |record|
38+
puts record.metadata
39+
end
40+
# Get all pages together (may take a *very* long time to complete)
41+
client.list_records.full.each do |record|
2942
puts record.metadata
3043
end
3144
```
3245

33-
See OAI::Client for more details
46+
See {OAI::Client} for more details
3447

3548
Server
3649
------
@@ -47,36 +60,28 @@ The OAI provider library handles serving local content to other clients. Here's
4760
end
4861
```
4962

50-
See OAI::Provider for more details
63+
See {OAI::Provider} for more details
5164

5265
Interactive Harvester
5366
---------------------
5467

55-
The OAI-PMH client shell allows OAI Harvesting to be configured in an interactive manner. Typing 'oai' on the command line starts the shell. After initial configuration, the shell can be used to manage harvesting operations.
68+
The OAI-PMH client shell allows OAI Harvesting to be configured in an interactive manner. Typing `oai` on the command line starts the shell. After initial configuration, the shell can be used to manage harvesting operations.
5669

57-
See OAI::Harvester::Shell for more details
70+
See {OAI::Harvester::Shell} for more details
5871

5972
Installation
6073
------------
6174

62-
Normally the best way to install oai is from rubyforge using the gem
63-
command line tool:
75+
Normally the best way to install oai is as part of your `Gemfile`:
6476

65-
```
66-
% gem install oai
67-
```
68-
69-
If you're reading this you've presumably got the tarball or zip distribution.
70-
So you'll need to:
77+
source :rubygems
78+
gem 'oai'
7179

72-
```
73-
% rake package
74-
% gem install pkg/oai-x.y.z.gem
75-
```
80+
Alternately it can be installed globally using RubyGems:
7681

77-
Where x.y.z is the version of the gem that was generated.
82+
$ gem install oai
7883

7984
License
8085
-------
8186

82-
[Public Domain](http://creativecommons.org/publicdomain/zero/1.0/)
87+
[![CC0 - Public Domain](http://i.creativecommons.org/p/zero/1.0/88x15.png)](http://creativecommons.org/publicdomain/zero/1.0/)

Rakefile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ end
1010
Bundler::GemHelper.install_tasks
1111

1212
require 'rake/testtask'
13-
require 'rdoc/task'
13+
require 'yard'
1414

15-
task :default => ["test"]
15+
task :default => ["test", "yard"]
1616

1717
task :test => ["test:client", "test:provider", "test:activerecord_provider"]
1818

@@ -84,8 +84,7 @@ if RUBY_VERSION =~ /^1.8/
8484
end
8585
end
8686

87-
Rake::RDocTask.new('doc') do |rd|
88-
rd.rdoc_files.include("lib/**/*.rb", "README.md")
89-
rd.main = 'README.md'
90-
rd.rdoc_dir = 'doc'
87+
YARD::Rake::YardocTask.new do |t|
88+
t.files = ["lib/**/*.rb"]
89+
t.options = ['--output-dir', 'doc']
9190
end

lib/oai/client.rb

Lines changed: 73 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -26,57 +26,60 @@
2626

2727
module OAI
2828

29-
# A OAI::Client provides a client api for issuing OAI-PMH verbs against
29+
# A `OAI::Client` provides a client api for issuing OAI-PMH verbs against
3030
# a OAI-PMH server. The 6 OAI-PMH verbs translate directly to methods you
31-
# can call on a OAI::Client object. Verb arguments are passed as a hash:
31+
# can call on a `OAI::Client` object. Verb arguments are passed as a hash:
3232
#
33+
# ```ruby
3334
# client = OAI::Client.new 'http://www.pubmedcentral.gov/oai/oai.cgi'
3435
# record = client.get_record :identifier => 'oai:pubmedcentral.gov:13901'
3536
# for identifier in client.list_identifiers
3637
# puts identifier
3738
# end
39+
# ```
3840
#
39-
# It is worth noting that the api uses methods and parameter names with
40-
# underscores in them rather than studly caps. So above list_identifiers
41-
# and metadata_prefix are used instead of the listIdentifiers and
42-
# metadataPrefix used in the OAI-PMH specification.
41+
# It is worth noting that the API uses methods and parameter names with
42+
# underscores in them rather than studly caps. So above `list_identifiers`
43+
# and `metadata_prefix` are used instead of the `listIdentifiers` and
44+
# `metadataPrefix` used in the OAI-PMH specification.
4345
#
4446
# Also, the from and until arguments which specify dates should be passed
45-
# in as Date or DateTime objects depending on the granularity supported
47+
# in as `Date` or `DateTime` objects depending on the granularity supported
4648
# by the server.
4749
#
4850
# For detailed information on the arguments that can be used please consult
49-
# the OAI-PMH docs at:
50-
#
51-
# http://www.openarchives.org/OAI/openarchivesprotocol.html
51+
# the OAI-PMH docs at
52+
# <http://www.openarchives.org/OAI/openarchivesprotocol.html>.
5253

5354
class Client
5455

5556
# The constructor which must be passed a valid base url for an oai
5657
# service:
5758
#
58-
# client = OAI::Client.new 'http://www.pubmedcentral.gov/oai/oai.cgi'
59+
# client = OAI::Client.new 'http://www.pubmedcentral.gov/oai/oai.cgi'
5960
#
60-
# If you want to see debugging messages on STDERR use:
61+
# If you want to see debugging messages on `STDERR` use:
6162
#
62-
# client = OAI::Client.new 'http://example.com', :debug => true
63+
# client = OAI::Client.new 'http://example.com', :debug => true
6364
#
64-
# By default OAI verbs called on the client will return REXML::Element
65+
# By default OAI verbs called on the client will return `REXML::Element`
6566
# objects for metadata records, however if you wish you can use the
66-
# :parser option to indicate you want to use 'libxml' instead, and get
67-
# back XML::Node objects
67+
# `:parser` option to indicate you want to use `libxml` instead, and get
68+
# back `XML::Node` objects
6869
#
69-
# client = OAI::Client.new 'http://example.com', :parser => 'libxml'
70+
# client = OAI::Client.new 'http://example.com', :parser => 'libxml'
7071
#
7172
# You can configure the Faraday HTTP client by providing an alternate
7273
# Faraday instance:
7374
#
74-
# client = OAI::Client.new 'http://example.com', :http => Faraday.new { |c| }
75+
# ```ruby
76+
# client = OAI::Client.new 'http://example.com', :http => Faraday.new {|c|}
77+
# ```
7578
#
76-
# === HIGH PERFORMANCE
79+
# ### HIGH PERFORMANCE
7780
#
78-
# If you want to supercharge this api install libxml-ruby >= 0.3.8 and
79-
# use the :parser option when you construct your OAI::Client.
81+
# If you want to supercharge this api install `libxml-ruby >= 0.3.8` and
82+
# use the `:parser` option when you construct your `OAI::Client`.
8083
#
8184
def initialize(base_url, options={})
8285
@base = URI.parse base_url
@@ -113,57 +116,80 @@ def initialize(base_url, options={})
113116
end
114117
end
115118

116-
# Equivalent to a Identify request. You'll get back a OAI::IdentifyResponse
117-
# object which is essentially just a wrapper around a REXML::Document
118-
# for the response. If you created your client using the libxml
119-
# parser then you will get an XML::Node object instead.
120-
119+
# Equivalent to a `Identify` request.
120+
# You'll get back a `OAI::IdentifyResponse`
121+
# object which is essentially just a wrapper around a `REXML::Document`
122+
# for the response. If you created your client using the `libxml`
123+
# parser then you will get an `XML::Node` object instead.
121124
def identify
122125
OAI::IdentifyResponse.new(do_request('Identify'))
123126
end
124127

125-
# Equivalent to a ListMetadataFormats request. A ListMetadataFormatsResponse
126-
# object is returned to you.
128+
# Equivalent to a `ListMetadataFormats` request.
129+
# A `ListMetadataFormatsResponse` object is returned to you.
127130

128131
def list_metadata_formats(opts={})
129132
OAI::ListMetadataFormatsResponse.new(do_request('ListMetadataFormats', opts))
130133
end
131134

132-
# Equivalent to a ListIdentifiers request. Pass in :from, :until arguments
133-
# as Date or DateTime objects as appropriate depending on the granularity
134-
# supported by the server.
135-
135+
# Equivalent to a `ListIdentifiers` request. Pass in `:from`,
136+
# `:until` arguments as `Date` or `DateTime` objects as appropriate
137+
# depending on the granularity supported by the server.
138+
#
139+
# You can use seamless resumption with this verb, which allows you to
140+
# mitigate (to some extent) the lack of a `Count` verb:
141+
#
142+
# client.list_identifiers.full.count # Don't try this on PubMed though!
143+
#
136144
def list_identifiers(opts={})
137145
do_resumable(OAI::ListIdentifiersResponse, 'ListIdentifiers', opts)
138146
end
139147

140-
# Equivalent to a GetRecord request. You must supply an identifier
141-
# argument. You should get back a OAI::GetRecordResponse object
142-
# which you can extract a OAI::Record object from.
143-
148+
# Equivalent to a `GetRecord` request. You must supply an `:identifier`
149+
# argument. You should get back a `OAI::GetRecordResponse` object
150+
# which you can extract a `OAI::Record` object from.
144151
def get_record(opts={})
145152
OAI::GetRecordResponse.new(do_request('GetRecord', opts))
146153
end
147154

148-
# Equivalent to the ListRecords request. A ListRecordsResponse
155+
# Equivalent to the `ListRecords` request. A `ListRecordsResponse`
149156
# will be returned which you can use to iterate through records
150157
#
151-
# for record in client.list_records
152-
# puts record.metadata
153-
# end
154-
158+
# response = client.list_records
159+
# response.each do |record|
160+
# puts record.metadata
161+
# end
162+
#
163+
# Alternately, you can use seamless resumption to avoid handling
164+
# resumption tokens:
165+
#
166+
# client.list_records.full.each do |record|
167+
# puts record.metadata
168+
# end
169+
#
170+
# ### Memory Use
171+
# `:full` will avoid storing more than one page of records in
172+
# memory, but your use it in ways that override that behaviour. Be careful
173+
# to avoid using `client.list_records.full.entries` unless you really want
174+
# to hold all the records in the feed in memory!
155175
def list_records(opts={})
156176
do_resumable(OAI::ListRecordsResponse, 'ListRecords', opts)
157177
end
158178

159-
# Equivalent to the ListSets request. A ListSetsResponse object
179+
# Equivalent to the `ListSets` request. A `ListSetsResponse` object
160180
# will be returned which you can use for iterating through the
161-
# OAI::Set objects
181+
# `OAI::Set` objects
162182
#
163-
# for set in client.list_sets
164-
# puts set
165-
# end
166-
183+
# for set in client.list_sets
184+
# puts set
185+
# end
186+
#
187+
# A large number of sets is not unusual for some OAI-PMH feeds, so
188+
# using seamless resumption may be preferable:
189+
#
190+
# client.list_sets.full.each do |set|
191+
# puts set
192+
# end
167193
def list_sets(opts={})
168194
do_resumable(OAI::ListSetsResponse, 'ListSets', opts)
169195
end

lib/oai/client/list_records.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ module OAI
22

33
# allows for iteration across a list of records
44
#
5-
# for record in client.list_records :metadata_prefix => 'oai_dc':
6-
# puts record.metadata
7-
# end
5+
# client.list_records(:metadata_prefix => 'oai_dc').each do |record|
6+
# puts record.metadata
7+
# end
88
#
99
# you'll need to handle resumption tokens
1010

lib/oai/client/list_sets.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ module OAI
22

33
# allows for iteration of the sets found in a oai-pmh server
44
#
5-
# for set in client.list_sets
6-
# puts set
7-
# end
5+
# for set in client.list_sets
6+
# puts set
7+
# end
88

99
class ListSetsResponse < Response
1010
include Enumerable

lib/oai/client/record.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
module OAI
22

3-
# A class for representing a Record as returned from a GetRecord
4-
# or ListRecords request. Each record will have a header and metadata
5-
# attribute. The header is a OAI::Header object and the metadata is
6-
# a REXML::Element object for that chunk of XML.
3+
# A class for representing a Record as returned from a `GetRecord`
4+
# or `ListRecords` request. Each record will have a header and metadata
5+
# attribute. The header is a {OAI::Header} object and the metadata is
6+
# a `REXML::Element` object for that chunk of XML.
77
#
8-
# Note: if your OAI::Client was configured to use the 'libxml' parser
9-
# metadata will return a XML::Node object instead.
10-
8+
# Note: if your {OAI::Client} was configured to use the 'libxml' parser
9+
# metadata will return a `XML::Node` object instead.
1110
class Record
1211
include OAI::XPath
1312
attr_accessor :header, :metadata, :about

lib/oai/client/response.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ module OAI
22

33
# An OAI::Response contains entries and a resumption token. If a resumption token is present,
44
# then you must use it to fetch the rest of the entries for your query. For example:
5+
#
6+
# ```ruby
57
# # List all records in a given set
68
# client = OAI::Client.new 'http://my-oai-provider.example.com/oai'
79
# response = client.list_records :set => 'my_set_name'
@@ -13,7 +15,7 @@ module OAI
1315
# # Note: You do not need to pass the options hash again, just the verb and the resumption token
1416
# response = client.list_records :resumption_token => token if token
1517
# end
16-
18+
# ```
1719
class Response
1820
include OAI::XPath
1921
attr_reader :doc, :resumption_token, :resumption_block

0 commit comments

Comments
 (0)