Class: BlacklightOaiProvider::ResumptionToken
- Inherits:
-
OAI::Provider::ResumptionToken
- Object
- OAI::Provider::ResumptionToken
- BlacklightOaiProvider::ResumptionToken
- Defined in:
- lib/blacklight_oai_provider/resumption_token.rb
Class Method Summary collapse
-
.parse(token_string) ⇒ Object
parses a token string and returns a ResumptionToken.
-
.parse_date(str) ⇒ Object
Force date to be in UTC.
Instance Method Summary collapse
Class Method Details
.parse(token_string) ⇒ Object
parses a token string and returns a ResumptionToken
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/blacklight_oai_provider/resumption_token.rb', line 4 def self.parse(token_string) = {} total = nil 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] = parse_date(part.sub(/^f\(/, '').sub(/\)$/, '')) when /^u/ [:until] = parse_date(part.sub(/^u\(/, '').sub(/\)$/, '')) when /^t/ total = part.sub(/^t\(/, '').sub(/\)$/, '').to_i end end new(, nil, total) rescue StandardError raise OAI::ResumptionTokenException end |
.parse_date(str) ⇒ Object
Force date to be in UTC. If date does not have a timezone UTC is assumed. If date is a different timezone it is converted to UTC.
31 32 33 |
# File 'lib/blacklight_oai_provider/resumption_token.rb', line 31 def self.parse_date(str) ActiveSupport::TimeZone.new('UTC').parse(str) end |
Instance Method Details
#encode_conditions ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/blacklight_oai_provider/resumption_token.rb', line 35 def encode_conditions encoded_token = @prefix.to_s.dup encoded_token << ".s(#{set})" if set encoded_token << ".f(#{from.utc.xmlschema})" if from encoded_token << ".u(#{self.until.utc.xmlschema})" if self.until encoded_token << ".t(#{total})" if total encoded_token << ":#{last}" end |
#to_xml ⇒ Object
44 45 46 47 48 49 |
# File 'lib/blacklight_oai_provider/resumption_token.rb', line 44 def to_xml xml = Builder::XmlMarkup.new token = total && (last > total) ? '' : encode_conditions xml.resumptionToken(token, hash_of_attributes) xml.target! end |