Class: Qa::Authorities::Loc

Inherits:
AuthorityWithSubAuthority show all
Includes:
LocSubauthority, WebServiceBase
Defined in:
lib/qa/authorities/loc.rb

Instance Attribute Summary

Attributes included from WebServiceBase

#raw_response

Attributes inherited from AuthorityWithSubAuthority

#sub_authority

Instance Method Summary collapse

Methods included from LocSubauthority

#authorities, #datatypes, #get_url_for_authority, #preservation, #vocabularies

Methods included from WebServiceBase

#get_json, #request_options

Methods inherited from AuthorityWithSubAuthority

#initialize

Methods inherited from Base

#all, #full_record

Constructor Details

This class inherits a constructor from Qa::Authorities::AuthorityWithSubAuthority

Instance Method Details

#build_query_url(q) ⇒ Object



17
18
19
20
21
# File 'lib/qa/authorities/loc.rb', line 17

def build_query_url q
  escaped_query = URI.escape(q)
  authority_fragment = get_url_for_authority(sub_authority) + URI.escape(sub_authority)
  return "http://id.loc.gov/search/?q=#{escaped_query}&q=#{authority_fragment}&format=json"
end

#find(id) ⇒ Object



23
24
25
# File 'lib/qa/authorities/loc.rb', line 23

def find id
  get_json(find_url(id))
end

#find_url(id) ⇒ Object



27
28
29
# File 'lib/qa/authorities/loc.rb', line 27

def find_url id
  "http://id.loc.gov/authorities/#{@sub_authority}/#{id}.json"
end

#search(q) ⇒ Object



12
13
14
15
# File 'lib/qa/authorities/loc.rb', line 12

def search q
  @raw_response = get_json(build_query_url(q))
  parse_authority_response
end

#sub_authoritiesObject



8
9
10
# File 'lib/qa/authorities/loc.rb', line 8

def sub_authorities
  authorities + vocabularies + datatypes + preservation
end