class Qa::Authorities::Crossref::GenericAuthority

Attributes

subauthority[R]

Public Class Methods

new(subauthority) click to toggle source
Calls superclass method
# File lib/qa/authorities/crossref/generic_authority.rb, line 7
def initialize(subauthority)
  super()
  @subauthority = subauthority
end

Public Instance Methods

build_query_url(q) click to toggle source
# File lib/qa/authorities/crossref/generic_authority.rb, line 26
def build_query_url(q)
  query = ERB::Util.url_encode(untaint(q))
  "http://api.crossref.org/#{subauthority}?query=#{query}"
end
find(id) click to toggle source
# File lib/qa/authorities/crossref/generic_authority.rb, line 35
def find(id)
  json(find_url(id))
end
find_url(id) click to toggle source
# File lib/qa/authorities/crossref/generic_authority.rb, line 39
def find_url(id)
  "http://api.crossref.org/#{subauthority}/#{id}"
end
untaint(q) click to toggle source
# File lib/qa/authorities/crossref/generic_authority.rb, line 31
def untaint(q)
  q.gsub(/[^\w\s-]/, '')
end

Private Instance Methods

parse_authority_response(response) click to toggle source

Reformats the data received from the service

# File lib/qa/authorities/crossref/generic_authority.rb, line 46
def parse_authority_response(response)
  response['message']['items'].map do |result|
    case subauthority
    when 'funders'
      { id: result['id'],
        uri: result['uri'],
        label: label.call(result),
        value: result['name'] }
    when 'journals'
      { id: result['ISSN'].first,
        label: result['title'],
        publisher: result['publisher'],
        issn: result['ISSN'] }

    end
  end
end