qa 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. checksums.yaml +7 -0
  2. data/app/controllers/qa/terms_controller.rb +31 -24
  3. data/config/routes.rb +2 -0
  4. data/lib/qa/authorities.rb +3 -1
  5. data/lib/qa/authorities/base.rb +5 -32
  6. data/lib/qa/authorities/lcsh.rb +21 -26
  7. data/lib/qa/authorities/loc.rb +124 -164
  8. data/lib/qa/authorities/local.rb +22 -57
  9. data/lib/qa/authorities/local/subauthority.rb +61 -0
  10. data/lib/qa/authorities/mesh.rb +13 -6
  11. data/lib/qa/authorities/oclcts.rb +18 -29
  12. data/lib/qa/authorities/tgnlang.rb +38 -23
  13. data/lib/qa/authorities/web_service_base.rb +20 -0
  14. data/lib/qa/version.rb +1 -1
  15. data/spec/controllers/terms_controller_spec.rb +6 -2
  16. data/spec/fixtures/authorities/authority_B.yml +7 -7
  17. data/spec/fixtures/authorities/authority_D.yml +4 -0
  18. data/spec/internal/Gemfile +2 -2
  19. data/spec/internal/Gemfile.lock +42 -39
  20. data/spec/internal/config/initializers/secret_token.rb +1 -1
  21. data/spec/internal/config/routes.rb +1 -1
  22. data/spec/internal/db/development.sqlite3 +0 -0
  23. data/spec/internal/db/migrate/{20130930151844_create_qa_subject_mesh_terms.qa.rb → 20131106203101_create_qa_subject_mesh_terms.qa.rb} +0 -0
  24. data/spec/internal/db/migrate/{20130930151845_create_qa_mesh_tree.qa.rb → 20131106203102_create_qa_mesh_tree.qa.rb} +0 -0
  25. data/spec/internal/db/migrate/{20130930151846_add_term_lower_to_qa_subject_mesh_terms.qa.rb → 20131106203103_add_term_lower_to_qa_subject_mesh_terms.qa.rb} +0 -0
  26. data/spec/internal/db/schema.rb +1 -1
  27. data/spec/internal/db/test.sqlite3 +0 -0
  28. data/spec/internal/log/development.log +6436 -79
  29. data/spec/lib/authorities_lcsh_spec.rb +30 -41
  30. data/spec/lib/authorities_loc_spec.rb +4 -3
  31. data/spec/lib/authorities_local_spec.rb +63 -27
  32. data/spec/lib/authorities_mesh_spec.rb +8 -2
  33. data/spec/lib/authorities_oclcts_spec.rb +6 -5
  34. data/spec/lib/authorities_tgnlang_spec.rb +6 -9
  35. data/spec/spec_helper.rb +7 -0
  36. metadata +49 -55
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 873698ac06d737a85d38e567cfbc86a237c11726
4
+ data.tar.gz: aca833c7eaaf7b53e5181f9705828e6bdd64267d
5
+ SHA512:
6
+ metadata.gz: 48ff5de3dabe9ff003cd066d67ded425ac5782ecc5f493d41879832ab0d9bf047118f96b10d091656af0a866e1169e896a86d15958014b15091e1b3f6004d356
7
+ data.tar.gz: 860a602fc303ec68bdd76f7651a5d193c97ac2656fa281ee83b7c998acb9461d4800f73bd8c8a1d63b53591b446f315cff64854694fbda8e87f93d6b897f3e43
@@ -6,50 +6,57 @@ class Qa::TermsController < ApplicationController
6
6
 
7
7
  before_action :check_search_params, only:[:search]
8
8
  before_action :check_vocab_param, :check_authority, :check_sub_authority
9
-
9
+
10
10
  #search that returns all results
11
11
  def index
12
12
  #initialize the authority and run the search. if there's a sub-authority and it's valid, include that param
13
- @authority = authority_class.constantize.new(params[:q], params[:sub_authority])
14
-
15
- #parse the results
16
- @authority.parse_authority_response
17
-
13
+ @authority = authority_class.constantize.new
14
+ @authority.search(params[:q], params[:sub_authority])
15
+
18
16
  respond_to do |format|
19
- format.html { render :layout => false, :text => @authority.results }
20
- format.json { render :layout => false, :text => @authority.results }
17
+ format.html { render :layout => false, json: @authority.results }
18
+ format.json { render :layout => false, json: @authority.results }
21
19
  format.js { render :layout => false, :text => @authority.results }
22
20
  end
23
21
  end
24
-
22
+
25
23
  def search
26
-
27
24
  #convert wildcard to be URI encoded
28
25
  params[:q].gsub!("*", "%2A")
29
-
26
+
30
27
  #initialize the authority and run the search. if there's a sub-authority and it's valid, include that param
31
- @authority = authority_class.constantize.new(params[:q], params[:sub_authority])
32
-
33
- #parse the results
34
- @authority.parse_authority_response
35
-
28
+ @authority = authority_class.constantize.new
29
+ @authority.search(params[:q], params[:sub_authority])
30
+
36
31
  respond_to do |format|
37
- format.html { render :layout => false, :text => @authority.results }
38
- format.json { render :layout => false, :text => @authority.results }
32
+ format.html { render :layout => false, :text => @authority.results.to_json }
33
+ format.json { render :layout => false, :text => @authority.results.to_json }
39
34
  format.js { render :layout => false, :text => @authority.results }
40
35
  end
41
36
 
42
37
  end
43
38
 
39
+ def show
40
+ check_sub_authority
41
+ authority = authority_class.constantize.new
42
+ result = authority.get_full_record(params[:id], params[:sub_authority])
43
+
44
+ respond_to do |format|
45
+ format.html { render :layout => false, :text => result.to_json }
46
+ format.json { render :layout => false, :text => result.to_json }
47
+ format.js { render :layout => false, :text => result }
48
+ end
49
+ end
50
+
44
51
  def check_vocab_param
45
52
  unless params[:vocab].present?
46
- redirect_to :status => 400
53
+ head :bad_request
47
54
  end
48
55
  end
49
-
56
+
50
57
  def check_search_params
51
58
  unless params[:q].present? && params[:vocab].present?
52
- redirect_to :status => 400
59
+ head :bad_request
53
60
  end
54
61
  end
55
62
 
@@ -57,13 +64,13 @@ class Qa::TermsController < ApplicationController
57
64
  begin
58
65
  authority_class.constantize
59
66
  rescue
60
- redirect_to :status => 400
61
- end
67
+ head :bad_request
68
+ end
62
69
  end
63
70
 
64
71
  def check_sub_authority
65
72
  unless params[:sub_authority].nil?
66
- redirect_to :status => 400 unless authority_class.constantize.authority_valid?(params[:sub_authority])
73
+ head :bad_request unless authority_class.constantize.authority_valid?(params[:sub_authority])
67
74
  end
68
75
  end
69
76
 
@@ -4,4 +4,6 @@ Qa::Engine.routes.draw do
4
4
  match "/terms/:vocab" => "terms#index", :via=>:get
5
5
  match "/terms/:vocab/:sub_authority" => "terms#index", :via=>:get
6
6
  match "/terms" => "terms#index", :via=>:get
7
+ match "/show/:vocab/:id" => "terms#show", :via=>:get
8
+ match "/show/:vocab/:sub_authority/:id" => "terms#show", :via=>:get
7
9
  end
@@ -5,8 +5,10 @@ module Qa::Authorities
5
5
  autoload :Lcsh
6
6
  autoload :Loc
7
7
  autoload :Local
8
+ autoload :Subauthority, 'qa/authorities/local/subauthority'
8
9
  autoload :Mesh
9
10
  autoload :MeshTools
10
11
  autoload :Oclcts
11
12
  autoload :Tgnlang
12
- end
13
+ autoload :WebServiceBase
14
+ end
@@ -2,21 +2,13 @@ require 'curl'
2
2
 
3
3
  module Qa::Authorities
4
4
  class Base
5
- attr_accessor :response, :query_url, :raw_response
6
5
 
7
- def initialize(q, sub_authority='')
8
- # Implement Me and set self.query_url
9
-
10
- if self.query_url == nil
11
- raise Exception 'query url in your authorities lib is not set (implement in initialize)'
12
- end
13
-
14
- #Default implementation assumed query_url is set
15
- http = Curl.get(self.query_url) do |http|
16
- http.headers['Accept'] = 'application/json'
17
- end
6
+ # do an autocomplete search
7
+ def search(query, sub_authority=nil)
8
+ end
18
9
 
19
- self.raw_response = JSON.parse(http.body_str)
10
+ # return information on a specific record
11
+ def get_full_record(id, sub_authority=nil)
20
12
  end
21
13
 
22
14
  def self.authority_valid?(sub_authority)
@@ -27,24 +19,5 @@ module Qa::Authorities
27
19
  [] #Overwrite if you have sub_authorities
28
20
  end
29
21
 
30
- def parse_authority_response
31
- # Overwrite me unless your raw response needs no parsing
32
- self.response = self.raw_response
33
-
34
- end
35
-
36
- def get_full_record(id)
37
- # implement me
38
- {"id"=>id}.to_json
39
- end
40
-
41
- # Parse the result from LOC, and return an JSON array of terms that match the query.
42
- def results
43
- self.response.to_json
44
- end
45
-
46
- # TODO: there's other info in the self.response that might be worth making access to, such as
47
- # RDF links, etc.
48
-
49
22
  end
50
23
  end
@@ -1,46 +1,41 @@
1
1
  require 'uri'
2
2
 
3
3
  module Qa::Authorities
4
- class Lcsh < Qa::Authorities::Base
5
-
6
- # Initialze the Lcsh class with a query and get the http response from LOC's server.
7
- # This is set to a JSON object
8
- def initialize(q, sub_authority='')
9
- self.query_url= "http://id.loc.gov/authorities/suggest/?q=" + q
4
+ class Lcsh < Qa::Authorities::WebServiceBase
10
5
 
6
+ def initialize
11
7
  super
12
8
  end
13
9
 
14
- # Format response to the correct JSON structure
15
- def parse_authority_response
16
- self.response = build_response
17
- end
18
-
19
- def query
20
- self.raw_response[0]
21
- end
22
-
23
- def suggestions
24
- self.raw_response[1]
10
+ def search(q, sub_authority='')
11
+ query_url = "http://id.loc.gov/authorities/suggest/?q=" + q
12
+ json_terms = get_json(query_url)
13
+ self.response = build_response(json_terms)
25
14
  end
26
15
 
27
- def urls_for_suggestions
28
- self.raw_response[3]
16
+ def get_full_record(id, sub_authority)
29
17
  end
30
18
 
31
19
  private
32
20
 
33
- def build_response a = Array.new
34
- self.suggestions.each_index do |i|
35
- a << {"id"=>get_id_from_url(urls_for_suggestions[i]), "label"=>suggestions[i]}
21
+ def build_response(json_response)
22
+ a = Array.new
23
+ suggests = json_response[1].each
24
+ urls = json_response[3].each
25
+ loop do
26
+ begin
27
+ a << {"id"=>get_id_from_url(urls.next), "label"=>suggests.next }
28
+ rescue StopIteration
29
+ break
30
+ end
36
31
  end
37
- return a
32
+ self.response = a
38
33
  end
39
34
 
40
- def get_id_from_url url
35
+ def get_id_from_url(url)
41
36
  uri = URI(url)
42
- return uri.path.split(/\//).last
37
+ return uri.path.split('/').last
43
38
  end
44
39
 
45
40
  end
46
- end
41
+ end
@@ -1,200 +1,160 @@
1
1
  require 'uri'
2
2
 
3
3
  module Qa::Authorities
4
- class Loc < Qa::Authorities::Base
4
+ class Loc < Qa::Authorities::WebServiceBase
5
5
 
6
6
  # Initialze the Loc class with a query and get the http response from LOC's server.
7
7
  # This is set to a JSON object
8
- def initialize(q, sub_authority='')
8
+ def initialize
9
+ end
10
+
11
+ def search(q, sub_authority=nil)
12
+ if ! (sub_authority.nil? || Loc.sub_authorities.include?(sub_authority))
13
+ @raw_response = nil
14
+ @response = nil
15
+ return
16
+ end
9
17
  q += '*'
10
- authority_url = sub_authorityURL(sub_authority)
11
- self.query_url = "http://id.loc.gov/search/?q=#{q}&q=#{authority_url}&format=json"
18
+ authority_fragment = sub_authorityURL(sub_authority)
19
+ query_url = "http://id.loc.gov/search/?q=#{q}&q=#{authority_fragment}&format=json"
20
+ @raw_response = get_json(query_url)
21
+ @response = parse_authority_response(@raw_response)
22
+ end
12
23
 
13
- super
24
+ def self.sub_authority_table
25
+ @sub_authority_table ||=
26
+ begin
27
+ vocab_base_url = 'cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fvocabulary%2F'
28
+ authority_base_url = 'cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2F'
29
+ datatype_base_url = 'cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fdatatypes%2F'
30
+ vocab_preservation_base_url = 'cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fvocabulary%2Fpreservation%2F'
31
+ {
32
+ 'subjects' => authority_base_url,
33
+ 'names' => authority_base_url,
34
+ 'classification' => authority_base_url,
35
+ 'childrensSubjects' => authority_base_url,
36
+ 'genreForms' => authority_base_url,
37
+ 'graphicMaterials' => vocab_base_url,
38
+ 'organizations' => vocab_base_url,
39
+ 'relators' => vocab_base_url,
40
+ 'countries' => vocab_base_url,
41
+ 'geographicAreas' => vocab_base_url,
42
+ 'languages' => vocab_base_url,
43
+ 'iso639-1' => vocab_base_url,
44
+ 'iso639-2' => vocab_base_url,
45
+ 'iso639-5' => vocab_base_url,
46
+ 'edtf' => datatype_base_url,
47
+ 'preservation' => vocab_base_url,
48
+ 'actionsGranted' => vocab_base_url,
49
+ 'agentType' => vocab_base_url,
50
+ 'contentLocationType' => vocab_preservation_base_url,
51
+ 'copyrightStatus' => vocab_preservation_base_url,
52
+ 'cryptographicHashFunctions' => vocab_preservation_base_url,
53
+ 'environmentCharacteristic' => vocab_preservation_base_url,
54
+ 'environmentPurpose' => vocab_preservation_base_url,
55
+ 'eventRelatedAgentRole' => vocab_preservation_base_url,
56
+ 'eventRelatedObjectRole' => vocab_preservation_base_url,
57
+ 'eventType' => vocab_preservation_base_url,
58
+ 'formatRegistryRole' => vocab_preservation_base_url,
59
+ 'hardwareType' => vocab_preservation_base_url,
60
+ 'inhibitorTarget' => vocab_preservation_base_url,
61
+ 'inhibitorType' => vocab_preservation_base_url,
62
+ 'objectCategory' => vocab_preservation_base_url,
63
+ 'preservationLevelRole' => vocab_preservation_base_url,
64
+ 'relationshipSubType' => vocab_preservation_base_url,
65
+ 'relationshipType' => vocab_preservation_base_url,
66
+ 'rightsBasis' => vocab_preservation_base_url,
67
+ 'rightsRelatedAgentRole' => vocab_preservation_base_url,
68
+ 'signatureEncoding' => vocab_preservation_base_url,
69
+ 'signatureMethod' => vocab_preservation_base_url,
70
+ 'softwareType' => vocab_preservation_base_url,
71
+ 'storageMedium' => vocab_preservation_base_url
72
+ }
73
+ end
14
74
  end
15
75
 
76
+
16
77
  def sub_authorityURL(sub_authority)
17
- vocab_base_url = 'cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fvocabulary%2F'
18
- authority_base_url = 'cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2F'
19
- datatype_base_url = 'cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fdatatypes%2F'
20
- vocab_preservation_base_url = 'cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fvocabulary%2Fpreservation%2F'
21
-
22
- case sub_authority
23
- when 'subjects'
24
- return authority_base_url + URI.escape(sub_authority)
25
- when 'names'
26
- return authority_base_url + URI.escape(sub_authority)
27
- when 'classification'
28
- return authority_base_url + URI.escape(sub_authority)
29
- when 'childrensSubjects'
30
- return authority_base_url + URI.escape(sub_authority)
31
- when 'genreForms'
32
- return authority_base_url + URI.escape(sub_authority)
33
- when 'graphicMaterials'
34
- return vocab_base_url + URI.escape(sub_authority)
35
- when 'organizations'
36
- return vocab_base_url + URI.escape(sub_authority)
37
- when 'relators'
38
- return vocab_base_url + URI.escape(sub_authority)
39
- when 'countries'
40
- return vocab_base_url + URI.escape(sub_authority)
41
- when 'geographicAreas'
42
- return vocab_base_url + URI.escape(sub_authority)
43
- when 'languages'
44
- return vocab_base_url + URI.escape(sub_authority)
45
- when 'iso639-1'
46
- return vocab_base_url + URI.escape(sub_authority)
47
- when 'iso639-2'
48
- return vocab_base_url + URI.escape(sub_authority)
49
- when 'iso639-5'
50
- return vocab_base_url + URI.escape(sub_authority)
51
- when 'edtf'
52
- return datatype_base_url + URI.escape(sub_authority)
53
- when 'preservation'
54
- return vocab_base_url + URI.escape(sub_authority)
55
- when 'actionsGranted'
56
- return vocab_base_url + URI.escape(sub_authority)
57
- when 'agentType'
58
- return vocab_base_url + URI.escape(sub_authority)
59
- when 'contentLocationType'
60
- return vocab_preservation_base_url + URI.escape(sub_authority)
61
- when 'copyrightStatus'
62
- return vocab_preservation_base_url + URI.escape(sub_authority)
63
- when 'cryptographicHashFunctions'
64
- return vocab_preservation_base_url + URI.escape(sub_authority)
65
- when 'environmentCharacteristic'
66
- return vocab_preservation_base_url + URI.escape(sub_authority)
67
- when 'environmentPurpose'
68
- return vocab_preservation_base_url + URI.escape(sub_authority)
69
- when 'eventRelatedAgentRole'
70
- return vocab_preservation_base_url + URI.escape(sub_authority)
71
- when 'eventRelatedObjectRole'
72
- return vocab_preservation_base_url + URI.escape(sub_authority)
73
- when 'eventType'
74
- return vocab_preservation_base_url + URI.escape(sub_authority)
75
- when 'formatRegistryRole'
76
- return vocab_preservation_base_url + URI.escape(sub_authority)
77
- when 'hardwareType'
78
- return vocab_preservation_base_url + URI.escape(sub_authority)
79
- when 'inhibitorTarget'
80
- return vocab_preservation_base_url + URI.escape(sub_authority)
81
- when 'inhibitorType'
82
- return vocab_preservation_base_url + URI.escape(sub_authority)
83
- when 'objectCategory'
84
- return vocab_preservation_base_url + URI.escape(sub_authority)
85
- when 'preservationLevelRole'
86
- return vocab_preservation_base_url + URI.escape(sub_authority)
87
- when 'relationshipSubType'
88
- return vocab_preservation_base_url + URI.escape(sub_authority)
89
- when 'relationshipType'
90
- return vocab_preservation_base_url + URI.escape(sub_authority)
91
- when 'rightsBasis'
92
- return vocab_preservation_base_url + URI.escape(sub_authority)
93
- when 'rightsRelatedAgentRole'
94
- return vocab_preservation_base_url + URI.escape(sub_authority)
95
- when 'signatureEncoding'
96
- return vocab_preservation_base_url + URI.escape(sub_authority)
97
- when 'signatureMethod'
98
- return vocab_preservation_base_url + URI.escape(sub_authority)
99
- when 'softwareType'
100
- return vocab_preservation_base_url + URI.escape(sub_authority)
101
- when 'storageMedium'
102
- return vocab_preservation_base_url + URI.escape(sub_authority)
103
- else
104
- return ''
105
- end
78
+ base_url = Loc.sub_authority_table[sub_authority]
79
+ return "" if base_url.nil?
80
+ base_url + URI.escape(sub_authority)
81
+ end
82
+
83
+ def self.authority_valid?(authority)
84
+ self.sub_authorities.include?(authority)
106
85
  end
107
86
 
108
87
  def self.sub_authorities
109
- ['iso639-2', 'subjects', 'names', 'classification', 'childrensSubjects', 'genreForms', 'graphicMaterials', 'organizations', 'relators', 'countries', 'geographicAreas', 'languages', 'iso639-5', 'edtf', 'preservation', 'actionsGranted', 'agentType', 'contentLocationType', 'copyrightStatus', 'cryptographicHashFunctions', 'environmentCharacteristic', 'environmentPurpose', 'eventRelatedAgentRole', 'eventRelatedObjectRole', 'eventType', 'formatRegistryRole', 'hardwareType', 'inhibitorTarget', 'inhibitorType', 'objectCategory', 'preservationLevelRole', 'relationshipSubType', 'relationshipType', 'rightsBasis', 'rightsRelatedAgentRole', 'signatureEncoding', 'signatureMethod', 'softwareType', 'storageMedium']
88
+ @sub_authorities ||= sub_authority_table.keys
110
89
  end
111
90
 
112
91
 
113
- def parse_authority_response
92
+ def parse_authority_response(raw_response)
114
93
  result = []
115
- self.raw_response.each do |single_response|
116
- if single_response[0] == "atom:entry"
117
- id = nil
118
- label = ''
119
- single_response.each do |result_part|
120
- if(result_part[0] == 'atom:title')
121
- label = result_part[2]
122
- end
123
-
124
- if(result_part[0] == 'atom:id')
125
- id = result_part[2]
126
- end
127
-
94
+ raw_response.each do |single_response|
95
+ next if single_response[0] != "atom:entry"
96
+ id = nil
97
+ label = ''
98
+ single_response.each do |result_part|
99
+ case result_part[0]
100
+ when 'atom:title'
101
+ label = result_part[2]
102
+ when 'atom:id'
103
+ id = result_part[2]
128
104
  end
129
-
130
- id ||= label
131
- result << {"id"=>id, "label"=>label}
132
-
133
105
  end
106
+
107
+ id ||= label
108
+ result << {"id"=>id, "label"=>label}
134
109
  end
135
- self.response = result
110
+ result
136
111
  end
137
112
 
138
- def get_full_record(id)
139
- full_record = nil
140
- parsed_result = {}
141
- self.raw_response.each do |single_response|
142
- if single_response[0] == "atom:entry"
143
-
144
- single_response.each do |result_part|
145
- if(result_part[0] == 'atom:title')
146
- if id == result_part[2]
147
- full_record = single_response
148
- end
149
- end
150
-
151
- if(result_part[0] == 'atom:id')
152
- if id == result_part[2]
153
- full_record = single_response
154
- end
155
- end
156
-
113
+ def find_record_in_response(raw_response, id)
114
+ raw_response.each do |single_response|
115
+ next if single_response[0] != "atom:entry"
116
+ single_response.each do |result_part|
117
+ if (result_part[0] == 'atom:title' ||
118
+ result_part[0] == 'atom:id') && id == result_part[2]
119
+ return single_response
157
120
  end
158
-
159
121
  end
160
122
  end
123
+ return nil
124
+ end
161
125
 
126
+ def get_full_record(id, sub_authority)
127
+ search(id, sub_authority)
128
+ full_record = find_record_in_response(@raw_response, id)
162
129
 
163
- if full_record != nil
164
- full_record.each do |section|
165
- if section.class == Array
166
- label = section[0].split(':').last.to_s
167
- case label
168
- when 'title'
169
- parsed_result[label] = section[2]
170
- when 'link'
171
- if section[1]['type'] != nil
172
- parsed_result[label + "||#{section[1]['type']}"] = section[1]["href"]
173
- else
174
- parsed_result[label] = section[1]["href"]
175
- end
176
- when 'id'
177
- parsed_result[label] = section[2]
178
- when 'author'
179
- author_list = []
180
- #FIXME: Find example with two authors to better understand this data.
181
- author_list << section[2][2]
182
- parsed_result[label] = author_list
183
- when 'updated'
184
- parsed_result[label] = section[2]
185
- when 'created'
186
- parsed_result[label] = section[2]
187
- end
130
+ if full_record.nil?
131
+ # record not found
132
+ return {}
133
+ end
188
134
 
135
+ parsed_result = {}
136
+ full_record.each do |section|
137
+ if section.class == Array
138
+ label = section[0].split(':').last.to_s
139
+ case label
140
+ when 'title', 'id', 'updated', 'created'
141
+ parsed_result[label] = section[2]
142
+ when 'link'
143
+ if section[1]['type'] != nil
144
+ parsed_result[label + "||#{section[1]['type']}"] = section[1]["href"]
145
+ else
146
+ parsed_result[label] = section[1]["href"]
147
+ end
148
+ when 'author'
149
+ author_list = []
150
+ #FIXME: Find example with two authors to better understand this data.
151
+ author_list << section[2][2]
152
+ parsed_result[label] = author_list
189
153
  end
190
154
  end
191
- else
192
- raise Exception 'Lookup without using a result search first not implemented yet'
193
155
  end
194
-
195
156
  parsed_result
196
-
197
157
  end
198
158
 
199
159
  end
200
- end
160
+ end