Class: Qa::Authorities::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/qa/authorities/base.rb

Direct Known Subclasses

Lcsh, Loc, Local, Oclcts

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(q, sub_authority = '') ⇒ Base

Returns a new instance of Base.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/qa/authorities/base.rb', line 7

def initialize(q, sub_authority='')
  # Implement Me and set self.query_url

  if self.query_url == nil
    raise Exception 'query url in your authorities lib is not set (implement in initialize)'
  end

  #Default implementation assumed query_url is set
  http = Curl.get(self.query_url) do |http|
    http.headers['Accept'] = 'application/json'
  end

  self.raw_response = JSON.parse(http.body_str)
end

Instance Attribute Details

#query_urlObject

Returns the value of attribute query_url.



5
6
7
# File 'lib/qa/authorities/base.rb', line 5

def query_url
  @query_url
end

#raw_responseObject

Returns the value of attribute raw_response.



5
6
7
# File 'lib/qa/authorities/base.rb', line 5

def raw_response
  @raw_response
end

#responseObject

Returns the value of attribute response.



5
6
7
# File 'lib/qa/authorities/base.rb', line 5

def response
  @response
end

Class Method Details

.authority_valid?(sub_authority) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/qa/authorities/base.rb', line 22

def self.authority_valid?(sub_authority)
  sub_authority == nil || sub_authorities.include?(sub_authority)
end

.sub_authoritiesObject



26
27
28
# File 'lib/qa/authorities/base.rb', line 26

def self.sub_authorities
  [] #Overwrite if you have sub_authorities
end

Instance Method Details

#get_full_record(id) ⇒ Object



36
37
38
39
# File 'lib/qa/authorities/base.rb', line 36

def get_full_record(id)
  # implement me
  {"id"=>id}.to_json
end

#parse_authority_responseObject



30
31
32
33
34
# File 'lib/qa/authorities/base.rb', line 30

def parse_authority_response
  # Overwrite me unless your raw response needs no parsing
  self.response = self.raw_response

end

#resultsObject

Parse the result from LOC, and return an JSON array of terms that match the query.



42
43
44
# File 'lib/qa/authorities/base.rb', line 42

def results
  self.response.to_json
end