Class: OAI::Provider::ResumptionToken
- Inherits:
-
Object
- Object
- OAI::Provider::ResumptionToken
- Defined in:
- lib/oai/provider/resumption_token.rb
Overview
OAI::Provider::ResumptionToken
The ResumptionToken class forms the basis of paging query results. It provides several helper methods for dealing with resumption tokens.
Instance Attribute Summary collapse
-
#expiration ⇒ Object
readonly
Returns the value of attribute expiration.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#last ⇒ Object
readonly
Returns the value of attribute last.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#set ⇒ Object
readonly
Returns the value of attribute set.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
-
#until ⇒ Object
readonly
Returns the value of attribute until.
Class Method Summary collapse
-
.extract_format(token_string) ⇒ Object
extracts the metadata prefix from a token string.
-
.parse(token_string) ⇒ Object
parses a token string and returns a ResumptionToken.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(options, expiration = nil, total = nil) ⇒ ResumptionToken
constructor
A new instance of ResumptionToken.
-
#next(last) ⇒ Object
convenience method for setting the offset of the next set of results.
-
#to_conditions_hash ⇒ Object
return a hash containing just the model selection parameters.
-
#to_s ⇒ Object
return the a string representation of the token minus the offset.
-
#to_xml ⇒ Object
output an xml resumption token.
Constructor Details
#initialize(options, expiration = nil, total = nil) ⇒ ResumptionToken
Returns a new instance of ResumptionToken.
44 45 46 47 48 49 50 51 52 |
# File 'lib/oai/provider/resumption_token.rb', line 44 def initialize(, expiration = nil, total = nil) @prefix = [:metadata_prefix] @set = [:set] @last = [:last] @from = [:from] if [:from] @until = [:until] if [:until] @expiration = expiration if expiration @total = total if total end |
Instance Attribute Details
#expiration ⇒ Object (readonly)
Returns the value of attribute expiration.
12 13 14 |
# File 'lib/oai/provider/resumption_token.rb', line 12 def expiration @expiration end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
12 13 14 |
# File 'lib/oai/provider/resumption_token.rb', line 12 def from @from end |
#last ⇒ Object (readonly)
Returns the value of attribute last.
12 13 14 |
# File 'lib/oai/provider/resumption_token.rb', line 12 def last @last end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
12 13 14 |
# File 'lib/oai/provider/resumption_token.rb', line 12 def prefix @prefix end |
#set ⇒ Object (readonly)
Returns the value of attribute set.
12 13 14 |
# File 'lib/oai/provider/resumption_token.rb', line 12 def set @set end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
12 13 14 |
# File 'lib/oai/provider/resumption_token.rb', line 12 def total @total end |
#until ⇒ Object (readonly)
Returns the value of attribute until.
12 13 14 |
# File 'lib/oai/provider/resumption_token.rb', line 12 def until @until end |
Class Method Details
.extract_format(token_string) ⇒ Object
extracts the metadata prefix from a token string
40 41 42 |
# File 'lib/oai/provider/resumption_token.rb', line 40 def self.extract_format(token_string) return token_string.split('.')[0] end |
.parse(token_string) ⇒ Object
parses a token string and returns a ResumptionToken
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/oai/provider/resumption_token.rb', line 15 def self.parse(token_string) begin = {} matches = /(.+):(\d+)$/.match(token_string) [:last] = matches.captures[1].to_i parts = matches.captures[0].split('.') [:metadata_prefix] = parts.shift parts.each do |part| case part when /^s/ [:set] = part.sub(/^s\(/, '').sub(/\)$/, '') when /^f/ [:from] = Time.parse(part.sub(/^f\(/, '').sub(/\)$/, '')).localtime when /^u/ [:until] = Time.parse(part.sub(/^u\(/, '').sub(/\)$/, '')).localtime end end self.new() rescue => err raise OAI::ResumptionTokenException.new end end |
Instance Method Details
#==(other) ⇒ Object
60 61 62 63 64 |
# File 'lib/oai/provider/resumption_token.rb', line 60 def ==(other) prefix == other.prefix and set == other.set and from == other.from and self.until == other.until and last == other.last and expiration == other.expiration and total == other.total end |
#next(last) ⇒ Object
convenience method for setting the offset of the next set of results
55 56 57 58 |
# File 'lib/oai/provider/resumption_token.rb', line 55 def next(last) @last = last self end |
#to_conditions_hash ⇒ Object
return a hash containing just the model selection parameters
74 75 76 77 78 79 80 |
# File 'lib/oai/provider/resumption_token.rb', line 74 def to_conditions_hash conditions = {:metadata_prefix => self.prefix } conditions[:set] = self.set if self.set conditions[:from] = self.from if self.from conditions[:until] = self.until if self.until conditions end |
#to_s ⇒ Object
return the a string representation of the token minus the offset
83 84 85 |
# File 'lib/oai/provider/resumption_token.rb', line 83 def to_s encode_conditions.gsub(/:\w+?$/, '') end |
#to_xml ⇒ Object
output an xml resumption token
67 68 69 70 71 |
# File 'lib/oai/provider/resumption_token.rb', line 67 def to_xml xml = Builder::XmlMarkup.new xml.resumptionToken(encode_conditions, hash_of_attributes) xml.target! end |