Class: EDSApi::EDSAPIRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/edsapi_wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(results_record) ⇒ EDSAPIRecord

Returns a new instance of EDSAPIRecord.



53
54
55
# File 'lib/edsapi_wrapper.rb', line 53

def initialize(results_record)
	@record = results_record;
end

Instance Attribute Details

#recordObject

Returns the value of attribute record.



51
52
53
# File 'lib/edsapi_wrapper.rb', line 51

def record
  @record
end

Instance Method Details

#abstractObject



273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/edsapi_wrapper.rb', line 273

def abstract
	items = @record.fetch('Items',{})
	if items.count > 0
		items.each do |item|
			if item["Group"] == "Ab"
				return item["Data"]
			end
		end
	end

	return nil
end


450
451
452
453
454
# File 'lib/edsapi_wrapper.rb', line 450

def all_links
	links = self.fulltext_links
	links = links + self.nonfulltext_links
	return links
end

#anObject



61
62
63
# File 'lib/edsapi_wrapper.rb', line 61

def an
	@record["Header"]["An"].to_s
end

#authorsObject

end title_raw



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/edsapi_wrapper.rb', line 150

def authors

	items = @record.fetch('Items',{})
	if items.count > 0
		items.each do |item|
			if item["Group"] == "Au"
				return item["Data"]
			end
		end
	end

	contributors = @record.fetch('RecordInfo', {}).fetch('BibRecord', {}).fetch('BibRelationships', {}).fetch('HasContributorRelationships', {})

	if contributors.count > 0
		authors = []
		contributors.each do |contributor|
			names = contributor.fetch('PersonEntity',{})
			authors.push(names['Name']['NameFull'])
		end
		author_str = authors.join("; ")
		return author_str
	end

	return nil
end

#authors_rawObject



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/edsapi_wrapper.rb', line 176

def authors_raw

	contributors = @record.fetch('RecordInfo', {}).fetch('BibRecord', {}).fetch('BibRelationships', {}).fetch('HasContributorRelationships', {})

	if contributors.count > 0
		authors = []
		contributors.each do |contributor|
			names = contributor.fetch('PersonEntity',{})
			authors.push(names['Name']['NameFull'])
		end
		return authors
	end

	items = @record.fetch('Items',{})
	if items.count > 0
		items.each do |item|
			if item["Group"] == "Au"
				return [item["Data"]]
			end
		end
	end

	return []
end


579
580
581
582
583
584
# File 'lib/edsapi_wrapper.rb', line 579

def best_fulltext_link
	if self.fulltext_links.count > 0
		return self.fulltext_links[0]
	end
	return {}
end

#db_labelObject



85
86
87
88
89
90
91
# File 'lib/edsapi_wrapper.rb', line 85

def db_label
	if DB_LABEL_LOOKUP.key?(self.dbid.upcase)
		dblabel = DB_LABEL_LOOKUP[self.dbid.upcase];
	else
		dblabel = @record["Header"]["DbLabel"]
	end
end

#dbidObject



65
66
67
# File 'lib/edsapi_wrapper.rb', line 65

def dbid
	@record["Header"]["DbId"].to_s
end

#doiObject



345
346
347
348
349
350
351
352
353
354
355
356
357
# File 'lib/edsapi_wrapper.rb', line 345

def doi
	ispartof = @record.fetch('RecordInfo', {}).fetch('BibRecord', {}).fetch('BibEntity', {}).fetch('Identifiers', {})

	if ispartof.count > 0
		ispartof.each do |ids|
			if ids["Type"] == "doi"
				return ids["Value"]
			end
		end
	end

	return nil
end


456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
# File 'lib/edsapi_wrapper.rb', line 456

def fulltext_links

	links = []

	ebscolinks = @record.fetch('FullText',{}).fetch('Links',{})
	if ebscolinks.count > 0
		ebscolinks.each do |ebscolink|
			if ebscolink["Type"] == "pdflink"
				link_label = "PDF Full Text"
				link_icon = "PDF Full Text Icon"
				if ebscolink.key?("Url")
					link_url = ebscolink["Url"]
				else
					link_url = "detail";
				end
				links.push({url: link_url, label: link_label, icon: link_icon, type: "pdf"})
			end
		end
	end

	htmlfulltextcheck = @record.fetch('FullText',{}).fetch('Text',{}).fetch('Availability',0)
	if htmlfulltextcheck == "1"
		link_url = "detail"
		link_label = "Full Text in Browser"
		link_icon = "Full Text in Browser Icon"
		links.push({url: link_url, label: link_label, icon: link_icon, type: "html"})
	end

	if ebscolinks.count > 0
		ebscolinks.each do |ebscolink|
			if ebscolink["Type"] == "ebook-pdf"
				link_label = "PDF eBook Full Text"
				link_icon = "PDF eBook Full Text Icon"
				if ebscolink.key?("Url")
					link_url = ebscolink["Url"]
				else
					link_url = "detail";
				end
				links.push({url: link_url, label: link_label, icon: link_icon, type: "ebook-pdf"})
			end
		end
	end

	if ebscolinks.count > 0
		ebscolinks.each do |ebscolink|
			if ebscolink["Type"] == "ebook-epub"
				link_label = "ePub eBook Full Text"
				link_icon = "ePub eBook Full Text Icon"
				if ebscolink.key?("Url")
					link_url = ebscolink["Url"]
				else
					link_url = "detail";
				end
				links.push({url: link_url, label: link_label, icon: link_icon, type: "ebook-epub"})
			end
		end
	end

	items = @record.fetch('Items',{})
	if items.count > 0
		items.each do |item|
			if item["Group"] == "URL"
				if item["Data"].include? "linkTerm=""
					link_start = item["Data"].index("linkTerm="")+15;
					link_url = item["Data"][link_start..-1]
					link_end = link_url.index(""")-1
					link_url = link_url[0..link_end]
					link_label_start = item["Data"].index("link>")+8
					link_label = item["Data"][link_label_start..-1]
					link_label = link_label.strip
				else
					link_url = item["Data"]
					link_label = item["Label"]
				end
				link_icon = "Catalog Link Icon"
				links.push({url: link_url, label: link_label, icon: link_icon, type: "cataloglink"})
			end
		end
	end

	if ebscolinks.count > 0
		ebscolinks.each do |ebscolink|
			if ebscolink["Type"] == "other"
				link_label = "Linked Full Text"
				link_icon = "Linked Full Text Icon"
				if ebscolink.key?("Url")
					link_url = ebscolink["Url"]
				else
					link_url = "detail";
				end
				links.push({url: link_url, label: link_label, icon: link_icon, type: "smartlinks+"})
			end
		end
	end

	ft_customlinks = @record.fetch('FullText',{}).fetch('CustomLinks',{})
	if ft_customlinks.count > 0
		ft_customlinks.each do |ft_customlink|
			link_url = ft_customlink["Url"]
			link_label = ft_customlink["Text"]
			link_icon = ft_customlink["Icon"]
			links.push({url: link_url, label: link_label, icon: link_icon, type: "customlink-fulltext"})
		end
	end

	return links
end

#html_fulltextObject



286
287
288
289
290
291
292
# File 'lib/edsapi_wrapper.rb', line 286

def html_fulltext
	htmlfulltextcheck = @record.fetch('FullText',{}).fetch('Text',{}).fetch('Availability',0)
	if htmlfulltextcheck == "1"
		return @record.fetch('FullText',{}).fetch('Text',{})["Value"]
	end
	return nil
end

#images(size_requested = "all") ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/edsapi_wrapper.rb', line 93

def images (size_requested = "all")
	returned_images = []

	images = @record.fetch('ImageInfo', {})
	if images.count > 0
		images.each do |image|
			if size_requested == image["Size"] || size_requested == "all"
				returned_images.push({size: image["Size"], src: image["Target"]})
			end
		end
	end
	return returned_images
end

#isbnsObject



359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
# File 'lib/edsapi_wrapper.rb', line 359

def isbns

	ispartof = @record.fetch('RecordInfo', {}).fetch('BibRecord', {}).fetch('BibRelationships', {}).fetch('IsPartOfRelationships', {})

	if ispartof.count > 0
		issns = []
		ispartof.each do |part_of|
			ids = part_of.fetch('BibEntity',{}).fetch('Identifiers',{})
			ids.each do |id|
				if id["Type"].include?("isbn") && !id["Type"].include?("locals")
					issns.push(id)
				end
			end
		end
		return issns
	end
	return []
end

#issnsObject



378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# File 'lib/edsapi_wrapper.rb', line 378

def issns

ispartof = @record.fetch('RecordInfo', {}).fetch('BibRecord', {}).fetch('BibRelationships', {}).fetch('IsPartOfRelationships', {})

if ispartof.count > 0
	issns = []
	ispartof.each do |part_of|
		ids = part_of.fetch('BibEntity',{}).fetch('Identifiers',{})
		ids.each do |id|
			if id["Type"].include?("issn") && !id["Type"].include?("locals")
				issns.push(id)
			end
		end
	end
	return issns
end
return []
end

#languagesObject



251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/edsapi_wrapper.rb', line 251

def languages
	language_section = @record.fetch('RecordInfo', {}).fetch('BibRecord', {}).fetch('BibEntity', {}).fetch('Languages', {})

	if language_section.count > 0
		langs = []
		language_section.each do |language|
			langs.push(language["Text"])
		end
		return langs
	end
	return []
end


564
565
566
567
568
569
570
571
572
573
574
575
576
577
# File 'lib/edsapi_wrapper.rb', line 564

def nonfulltext_links
	links = []
	other_customlinks = @record.fetch('CustomLinks',{})
	if other_customlinks.count > 0
		other_customlinks.each do |other_customlink|
			link_url = other_customlink["Url"]
			link_label = other_customlink["Text"]
			link_icon = other_customlink["Icon"]
			links.push({url: link_url, label: link_label, icon: link_icon, type: "customlink-other"})
		end
	end

	return links
end

#numberingObject



328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/edsapi_wrapper.rb', line 328

def numbering
	ispartof = @record.fetch('RecordInfo', {}).fetch('BibRecord', {}).fetch('BibRelationships', {}).fetch('IsPartOfRelationships', {})

	if ispartof.count > 0
		numbering = []
		ispartof.each do |contributor|
			nums = contributor.fetch('BibEntity',{}).fetch('Numbering',{})
			nums.each do |num|
				numbering.push(num)
			end
		end
		return numbering
	end

	return []
end

#pagesObject



264
265
266
267
268
269
270
271
# File 'lib/edsapi_wrapper.rb', line 264

def pages
	pagination_section = @record.fetch('RecordInfo', {}).fetch('BibRecord', {}).fetch('BibEntity', {}).fetch('PhysicalDescription', {})

	if pagination_section.count > 0
		return pagination_section["Pagination"]
	end
	return {}
end


69
70
71
# File 'lib/edsapi_wrapper.rb', line 69

def plink
	@record["Header"]["PLink"]
end

#pubdateObject



435
436
437
438
439
440
441
442
443
444
445
446
447
448
# File 'lib/edsapi_wrapper.rb', line 435

def pubdate
	ispartofs = @record.fetch('RecordInfo', {}).fetch('BibRecord', {}).fetch('BibRelationships', {}).fetch('IsPartOfRelationships', {})
	if ispartofs.count > 0
		dates = ispartofs[0]["BibEntity"].fetch('Dates',{})
		if dates.count > 0
			dates.each do |date|
				if date["Type"] == "published"
					return date["Y"]+"-"+date["M"]+"-"+date["D"]
				end
			end
		end
	end
	return nil
end

#pubtypeObject



77
78
79
# File 'lib/edsapi_wrapper.rb', line 77

def pubtype
	@record["Header"]["PubType"]
end

#pubtype_idObject



81
82
83
# File 'lib/edsapi_wrapper.rb', line 81

def pubtype_id
	@record["Header"]["PubTypeId"]
end

#pubyearObject



420
421
422
423
424
425
426
427
428
429
430
431
432
433
# File 'lib/edsapi_wrapper.rb', line 420

def pubyear
	ispartofs = @record.fetch('RecordInfo', {}).fetch('BibRecord', {}).fetch('BibRelationships', {}).fetch('IsPartOfRelationships', {})
	if ispartofs.count > 0
		dates = ispartofs[0]["BibEntity"].fetch('Dates',{})
		if dates.count > 0
			dates.each do |date|
				if date["Type"] == "published"
					return date["Y"]
				end
			end
		end
	end
	return nil
end

#resultidObject



57
58
59
# File 'lib/edsapi_wrapper.rb', line 57

def resultid
	@record["ResultId"]
end

#retrieve_optionsObject



586
587
588
589
590
591
# File 'lib/edsapi_wrapper.rb', line 586

def retrieve_options
	options = {}
	options['an'] = self.an
	options['dbid'] = self.dbid
	return options
end

#scoreObject



73
74
75
# File 'lib/edsapi_wrapper.rb', line 73

def score
	@record["Header"]["RelevancyScore"]
end

#sourceObject



294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/edsapi_wrapper.rb', line 294

def source

	items = @record.fetch('Items',{})
	if items.count > 0
		items.each do |item|
			if item["Group"] == "Src"
				return item["Data"]
			end
		end
	end

	return nil
end

#source_isbnObject



397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# File 'lib/edsapi_wrapper.rb', line 397

def source_isbn
  unless self.source.nil?

		ispartof = @record.fetch('RecordInfo', {}).fetch('BibRecord', {}).fetch('BibRelationships', {}).fetch('IsPartOfRelationships', {})

		if ispartof.count > 0
			issns = []
			ispartof.each do |part_of|
				ids = part_of.fetch('BibEntity',{}).fetch('Identifiers',{})
				ids.each do |id|
					if id["Type"].include?("isbn") && !id["Type"].include?("locals")
						issns.push(id)
					end
				end
			end
			return issns
		end
  end
	return []
end

#source_titleObject



308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'lib/edsapi_wrapper.rb', line 308

def source_title

	unless self.source.nil?
		ispartof = @record.fetch('RecordInfo', {}).fetch('BibRecord', {}).fetch('BibRelationships', {}).fetch('IsPartOfRelationships', {})

		if ispartof.count > 0
			ispartof.each do |contributor|
				titles = contributor.fetch('BibEntity',{}).fetch('Titles',{})
				titles.each do |title_src|
					if title_src["Type"] == "main"
						return title_src["TitleFull"]
					end
				end
			end
		end
	end
	return nil

end

#subjectsObject



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/edsapi_wrapper.rb', line 202

def subjects

	items = @record.fetch('Items',{})
	if items.count > 0
		items.each do |item|
			if item["Group"] == "Su"
				return item["Data"]
			end
		end
	end

	subjects = @record.fetch('RecordInfo', {}).fetch('BibRecord', {}).fetch('BibEntity', {}).fetch('Subjects', {})

	if subjects.count > 0
		subs = []
		subjects.each do |subject|
			subs.push(subject["SubjectFull"])
		end
		subs_str = subs.join("; ")
		return subs_str
	end

	return nil
end

#subjects_rawObject



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/edsapi_wrapper.rb', line 227

def subjects_raw

	subjects = @record.fetch('RecordInfo', {}).fetch('BibRecord', {}).fetch('BibEntity', {}).fetch('Subjects', {})

	if subjects.count > 0
		subs = []
		subjects.each do |subject|
			subs.push(subject)
		end
		return subs
	end

	items = @record.fetch('Items',{})
	if items.count > 0
		items.each do |item|
			if item["Group"] == "Su"
				return [item["Data"]]
			end
		end
	end

	return []
end

#titleObject



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/edsapi_wrapper.rb', line 107

def title
	items = @record.fetch('Items',{})
	if items.count > 0
		items.each do |item|
			if item["Group"] == "Ti"
				return item["Data"]
			end
		end
	end

	titles = @record.fetch('RecordInfo', {}).fetch('BibRecord', {}).fetch('BibEntity', {}).fetch('Titles', {})
	if titles.count > 0
		titles.each do |title|
			if title["Type"] == "main"
				return title["TitleFull"]
			end
		end
	end

	return nil
end

#title_rawObject



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/edsapi_wrapper.rb', line 129

def title_raw
	titles = @record.fetch('RecordInfo', {}).fetch('BibRecord', {}).fetch('BibEntity', {}).fetch('Titles', {})
	if titles.count > 0
		titles.each do |title|
			if title["Type"] == "main"
				return title["TitleFull"]
			end
		end
	end
	items = @record.fetch('Items',{})
	if items.count > 0
		items.each do |item|
			if item["Group"] == "Ti"
				return item["Data"]
			end
		end
	end
	return nil
end