Class: EBSCO::EDS::Record
- Inherits:
-
Object
- Object
- EBSCO::EDS::Record
- Defined in:
- lib/ebsco/eds/record.rb
Overview
A single search result
Constant Summary collapse
- ATTRIBUTES =
[ :id, :eds_accession_number, :eds_database_id, :eds_database_name, :eds_access_level, :eds_relevancy_score, :eds_title, :eds_source_title, :eds_composed_title, :eds_other_titles, :eds_abstract, :eds_authors, :eds_author_affiliations, :eds_authors_composed, :eds_subjects, :eds_subjects_geographic, :eds_subjects_person, :eds_subjects_company, :eds_subjects_mesh, :eds_subjects_bisac, :eds_subjects_genre, :eds_author_supplied_keywords, :eds_descriptors, :eds_notes, :eds_subset, :eds_languages, :eds_page_count, :eds_page_start, :eds_physical_description, :eds_publication_type, :eds_publication_type_id, :eds_publication_date, :eds_publication_year, :eds_publication_info, :eds_publication_status, :eds_publisher, :eds_document_type, :eds_document_doi, :eds_document_oclc, :eds_issn_print, :eds_issns, :eds_isbn_print, :eds_isbn_electronic, :eds_isbns_related, :eds_isbns, :eds_series, :eds_volume, :eds_issue, :eds_covers, :eds_cover_thumb_url, :eds_cover_medium_url, :eds_fulltext_word_count, :eds_result_id, :eds_plink, :eds_ebook_pdf_fulltext_available, :eds_ebook_epub_fulltext_available, :eds_pdf_fulltext_available, :eds_html_fulltext_available, :eds_html_fulltext, :eds_images, :eds_quick_view_images, :eds_all_links, :eds_fulltext_links, :eds_non_fulltext_links, :eds_code_naics, :eds_abstract_supplied_copyright, # publication record attributes :eds_publication_id, :eds_publication_is_searchable, :eds_publication_scope_note, :eds_citation_exports, :eds_citation_styles ]
- KNOWN_ITEM_NAMES =
%w( URL Title TitleSource TitleAlt Abstract Note Author AffiliationAuthor Subject SubjectGeographic SubjectPerson SubjectCompany SubjectMESH SubjectBISAC SubjectGenre Subset Language PhysDesc TypePub DatePub TypeDocument DOI ISSN SeriesInfo FullTextWordCount AbstractSuppliedCopyright CodeNAICS NoteScope Publisher )
- KNOWN_ITEM_LABELS =
[ 'OCLC', 'Descriptors', 'Publication Information', 'Related ISBNs' ]
Instance Method Summary collapse
-
#add_extra_item_accessors(item) ⇒ Object
dynamically add item metadata as ‘eds_extra_ItemNameOrLabel’.
-
#add_protocol(url) ⇒ Object
add protocol if needed.
-
#add_subject_searchlinks(data) ⇒ Object
add searchlinks when they don’t exist.
-
#all_links ⇒ Object
A list of all available links.
- #attributes ⇒ Object
- #bib_authors ⇒ Object
- #bib_authors_list ⇒ Object
- #bib_doi ⇒ Object
- #bib_isbn_electronic ⇒ Object
- #bib_isbn_print ⇒ Object
-
#bib_isbns ⇒ Object
todo: make this generic and take an optional parameter for type.
- #bib_issn_electronic ⇒ Object
- #bib_issn_print ⇒ Object
- #bib_issns ⇒ Object
- #bib_issue ⇒ Object
- #bib_languages ⇒ Object
-
#bib_page_count ⇒ Object
def bib_pages @bib_entity.fetch(‘PhysicalDescription’, {})[‘Pagination’] end.
- #bib_page_start ⇒ Object
- #bib_publication_date ⇒ Object
- #bib_publication_month ⇒ Object
- #bib_publication_year ⇒ Object
-
#bib_source_title ⇒ Object
BIB - IS PART OF (journal, book) ====================================================================================.
- #bib_subjects ⇒ Object
-
#bib_title ⇒ Object
BIB ENTITY ====================================================================================.
- #bib_volume ⇒ Object
-
#cover_medium_url ⇒ Object
Cover image - medium size link.
-
#cover_thumb_url ⇒ Object
Cover image - thumbnail size link.
-
#fulltext_link(type = 'first') ⇒ Object
The first fulltext link.
-
#fulltext_links ⇒ Object
All available fulltext links.
- #get_item_data(options) ⇒ Object
-
#html_decode_and_sanitize(data, config = nil) ⇒ Object
Decode any html elements and then run it through sanitize to preserve entities (eg: ampersand) and strip out elements/attributes that aren’t explicitly whitelisted.
-
#html_fulltext ⇒ Object
Fulltext - RETRIEVE ONLY.
-
#html_fulltext_available ⇒ Object
Fulltext available.
-
#images(size_requested = 'all') ⇒ Object
List of cover images.
-
#initialize(results_record, eds_config = nil) ⇒ Record
constructor
Creates a search or retrieval result record.
-
#item_related_isbns ⇒ Object
related ISBNs.
-
#non_fulltext_links ⇒ Object
All available non-fulltext links.
-
#quick_view_images ⇒ Object
List of image quick view.
- #require_sanitize ⇒ Object
-
#retrieve_options ⇒ Object
Options hash containing accession number and database ID.
-
#sanitize_data(item) ⇒ Object
decode & sanitize html tags found in item data; apply any special transformations.
- #set_citation_exports(val) ⇒ Object
- #set_citation_styles(val) ⇒ Object
-
#source_title ⇒ Object
The source title (example: ‘Salem Press Encyclopedia’).
-
#title ⇒ Object
The title.
- #to_attr_hash ⇒ Object
- #to_solr ⇒ Object
Constructor Details
#initialize(results_record, eds_config = nil) ⇒ Record
Creates a search or retrieval result record
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 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 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/ebsco/eds/record.rb', line 134 def initialize(results_record, eds_config = nil) # translate all subject search link field codes to DE? @all_subjects_search_links = false if eds_config @all_subjects_search_links = eds_config[:all_subjects_search_links] end if ENV.has_key? 'EDS_ALL_SUBJECTS_SEARCH_LINKS' @all_subjects_search_links = ENV['EDS_ALL_SUBJECTS_SEARCH_LINKS'] end # decode and sanitize html in item data? @decode_sanitize_html = false if eds_config @decode_sanitize_html = eds_config[:decode_sanitize_html] end if ENV.has_key? 'EDS_DECODE_SANITIZE_HTML' @decode_sanitize_html = ENV['EDS_DECODE_SANITIZE_HTML'] end require_sanitize if @decode_sanitize_html if results_record.key? 'Record' @record = results_record['Record'] # single record returned by retrieve api else @record = results_record # set of records returned by search api end @items = @record.fetch('Items', {}) @bib_entity = @record.fetch('RecordInfo', {}).fetch('BibRecord', {}).fetch('BibEntity', {}) @bib_relationships = @record.fetch('RecordInfo', {}).fetch('BibRecord', {}).fetch('BibRelationships', {}) @bib_part = @record.fetch('RecordInfo', {}) .fetch('BibRecord', {}) .fetch('BibRelationships', {}) .fetch('IsPartOfRelationships', {})[0] @image_quick_view_items = @record.fetch('ImageQuickViewItems', {}) # accessors: @eds_result_id = @record['ResultId'] @eds_plink = @record['PLink'] @eds_accession_number = @record['Header']['An'].to_s @eds_database_id = @record['Header']['DbId'].to_s @eds_database_name = @record['Header']['DbLabel'] @eds_access_level = @record['Header']['AccessLevel'] @eds_relevancy_score = @record['Header']['RelevancyScore'] @id = @eds_database_id + '__' + @eds_accession_number @eds_title = title @eds_source_title = source_title @eds_composed_title = get_item_data({name: 'TitleSource'}) @eds_other_titles = get_item_data({name: 'TitleAlt'}) @eds_abstract = get_item_data({name: 'Abstract'}) @eds_authors = @eds_authors_composed = get_item_data({name: 'Author'}) @eds_author_affiliations = get_item_data({name: 'AffiliationAuthor'}) @eds_subjects = get_item_data({name: 'Subject', label: 'Subject Terms', group: 'Su'}) || get_item_data({name: 'Subject', label: 'Subject Indexing', group: 'Su'}) || get_item_data({name: 'Subject', label: 'Subject Category', group: 'Su'}) || get_item_data({name: 'Subject', label: 'KeyWords Plus', group: 'Su'}) || bib_subjects @eds_subjects_geographic = get_item_data({name: 'SubjectGeographic', label: 'Geographic Terms', group: 'Su'}) || get_item_data({name: 'Subject', label: 'Subject Geographic', group: 'Su'}) @eds_subjects_person = get_item_data({name: 'SubjectPerson'}) @eds_subjects_company = get_item_data({name: 'SubjectCompany'}) @eds_subjects_bisac = get_item_data({name: 'SubjectBISAC'}) @eds_subjects_mesh = get_item_data({name: 'SubjectMESH'}) @eds_subjects_genre = get_item_data({name: 'SubjectGenre'}) @eds_author_supplied_keywords = get_item_data({name: 'Keyword'}) @eds_notes = get_item_data({name: 'Note'}) @eds_subset = get_item_data({name: 'Subset'}) @eds_languages = get_item_data({name: 'Language'}) || bib_languages @eds_page_count = bib_page_count @eds_page_start = bib_page_start @eds_physical_description = get_item_data({name: 'PhysDesc'}) @eds_publication_type = @record['Header']['PubType'] || get_item_data({name: 'TypePub'}) @eds_publication_type_id = @record['Header']['PubTypeId'] @eds_publication_date = bib_publication_date || get_item_data({name: 'DatePub'}) @eds_publication_year = bib_publication_year || get_item_data({name: 'DatePub'}) @eds_publication_info = get_item_data({label: 'Publication Information'}) @eds_publication_status = get_item_data({label: 'Publication Status'}) @eds_publisher = get_item_data({name: 'Publisher'}) @eds_document_type = get_item_data({name: 'TypeDocument'}) @eds_document_doi = get_item_data({name: 'DOI'}) || bib_doi @eds_document_oclc = get_item_data({label: 'OCLC'}) @eds_issn_print = get_item_data({name: 'ISSN'}) || bib_issn_print @eds_issns = bib_issns @eds_isbn_print = bib_isbn_print @eds_isbns_related = @eds_isbn_electronic = bib_isbn_electronic @eds_isbns = bib_isbns || @eds_series = get_item_data({name: 'SeriesInfo'}) @eds_volume = bib_volume @eds_issue = bib_issue @eds_covers = images @eds_cover_thumb_url = cover_thumb_url @eds_cover_medium_url = cover_medium_url @eds_fulltext_word_count = get_item_data({name: 'FullTextWordCount'}).to_i @eds_html_fulltext_available = html_fulltext_available @eds_html_fulltext = html_fulltext @eds_images = images @eds_quick_view_images = quick_view_images @eds_all_links = all_links # init fulltext available props, reset by fulltext_links method later @eds_pdf_fulltext_available = false @eds_ebook_pdf_fulltext_available = false @eds_ebook_epub_fulltext_available = false @eds_fulltext_links = fulltext_links @eds_non_fulltext_links = non_fulltext_links @eds_code_naics = get_item_data({name: 'CodeNAICS'}) @eds_abstract_supplied_copyright = get_item_data({name: 'AbstractSuppliedCopyright'}) @eds_descriptors = get_item_data({label: 'Descriptors'}) @eds_publication_id = @record['Header']['PublicationId'] @eds_publication_is_searchable = @record['Header']['IsSearchable'] @eds_publication_scope_note = get_item_data({name: 'NoteScope'}) # add item metadata @items.each do |item| unless KNOWN_ITEM_NAMES.include?(item['Name']) || KNOWN_ITEM_LABELS.include?(item['Label']) add_extra_item_accessors(item) end end end |
Instance Method Details
#add_extra_item_accessors(item) ⇒ Object
dynamically add item metadata as ‘eds_extra_ItemNameOrLabel’
975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 |
# File 'lib/ebsco/eds/record.rb', line 975 def add_extra_item_accessors(item) key = item['Name'] ? item['Name'].gsub(/\s+/, '_') : item['Label'].gsub(/\s+/, '_') # NumberOther isn't always unique, concatenate the label if key == 'NumberOther' or key == 'Number_Other' key = 'number_other_' + item['Label'].gsub(/\s+/, '_') end value = item['Data'] unless key.nil? key = "eds_extras_#{key}" unless value.nil? self.class.class_eval { attr_accessor key } self.instance_variable_set "@#{key}", CGI.unescapeHTML(value) end end end |
#add_protocol(url) ⇒ Object
add protocol if needed
427 428 429 430 431 432 |
# File 'lib/ebsco/eds/record.rb', line 427 def add_protocol(url) unless url[/\Ahttp:\/\//] || url[/\Ahttps:\/\//] url = "https://#{url}" end url end |
#add_subject_searchlinks(data) ⇒ Object
add searchlinks when they don’t exist
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 |
# File 'lib/ebsco/eds/record.rb', line 1000 def add_subject_searchlinks(data) subjects = data if data.include? '<link ' subjects = bib_subjects subjects = subjects.map do |su| '<searchLink fieldCode="DE" term="%22' + su + '%22">' + su + '</searchLink>' end.join('<br />') end unless subjects.include? 'searchLink' subjects = subjects.split('<br />').map do |su| '<searchLink fieldCode="DE" term="%22' + su + '%22">' + su + '</searchLink>' end.join('<br />') end subjects end |
#all_links ⇒ Object
A list of all available links.
412 413 414 |
# File 'lib/ebsco/eds/record.rb', line 412 def all_links fulltext_links + non_fulltext_links end |
#attributes ⇒ Object
129 130 131 |
# File 'lib/ebsco/eds/record.rb', line 129 def attributes ATTRIBUTES.map{|attribute| self.send(attribute) } end |
#bib_authors ⇒ Object
571 572 573 574 575 576 577 |
# File 'lib/ebsco/eds/record.rb', line 571 def if @bib_relationships @bib_relationships.deep_find('NameFull').join('; ') else nil end end |
#bib_authors_list ⇒ Object
579 580 581 582 583 584 585 |
# File 'lib/ebsco/eds/record.rb', line 579 def if @bib_relationships @bib_relationships.deep_find('NameFull') else nil end end |
#bib_doi ⇒ Object
623 624 625 626 627 628 629 630 631 632 633 634 |
# File 'lib/ebsco/eds/record.rb', line 623 def bib_doi if @bib_entity && @bib_entity.fetch('Identifiers',{}).any? item_doi = @bib_entity.fetch('Identifiers',{}).find{|item| item['Type'] == 'doi'} if item_doi item_doi['Value'] else nil end else nil end end |
#bib_isbn_electronic ⇒ Object
704 705 706 707 708 709 710 711 712 713 714 715 |
# File 'lib/ebsco/eds/record.rb', line 704 def bib_isbn_electronic if @bib_part && @bib_part.fetch('BibEntity',{}).fetch('Identifiers',{}).any? item_isbn_e = @bib_part.fetch('BibEntity',{}).fetch('Identifiers',{}).find{|item| item['Type'] == 'isbn-electronic'} if item_isbn_e item_isbn_e['Value'] else nil end else nil end end |
#bib_isbn_print ⇒ Object
691 692 693 694 695 696 697 698 699 700 701 702 |
# File 'lib/ebsco/eds/record.rb', line 691 def bib_isbn_print if @bib_part && @bib_part.fetch('BibEntity',{}).fetch('Identifiers',{}).any? item_isbn_p = @bib_part.fetch('BibEntity',{}).fetch('Identifiers',{}).find{|item| item['Type'] == 'isbn-print'} if item_isbn_p item_isbn_p['Value'] else nil end else nil end end |
#bib_isbns ⇒ Object
todo: make this generic and take an optional parameter for type
718 719 720 721 722 723 724 725 726 727 728 |
# File 'lib/ebsco/eds/record.rb', line 718 def bib_isbns isbns = [] if @bib_part && @bib_part.fetch('BibEntity',{}).fetch('Identifiers',{}).any? @bib_part.fetch('BibEntity',{}).fetch('Identifiers',{}).each do |id| if id['Type'].include?('isbn') && !id['Type'].include?('locals') isbns.push(id['Value']) end end end isbns end |
#bib_issn_electronic ⇒ Object
666 667 668 669 670 671 672 673 674 675 676 677 |
# File 'lib/ebsco/eds/record.rb', line 666 def bib_issn_electronic if @bib_part && @bib_part.fetch('BibEntity',{}).fetch('Identifiers',{}).any? item_issn_e = @bib_part.fetch('BibEntity',{}).fetch('Identifiers',{}).find{|item| item['Type'] == 'issn-electronic'} if item_issn_e item_issn_e['Value'] else nil end else nil end end |
#bib_issn_print ⇒ Object
653 654 655 656 657 658 659 660 661 662 663 664 |
# File 'lib/ebsco/eds/record.rb', line 653 def bib_issn_print if @bib_part && @bib_part.fetch('BibEntity',{}).fetch('Identifiers',{}).any? item_issn_p = @bib_part.fetch('BibEntity',{}).fetch('Identifiers',{}).find{|item| item['Type'] == 'issn-print'} if item_issn_p item_issn_p['Value'] else nil end else nil end end |
#bib_issns ⇒ Object
679 680 681 682 683 684 685 686 687 688 689 |
# File 'lib/ebsco/eds/record.rb', line 679 def bib_issns issns = [] if @bib_part && @bib_part.fetch('BibEntity',{}).fetch('Identifiers',{}).any? @bib_part.fetch('BibEntity',{}).fetch('Identifiers',{}).each do |id| if id['Type'].include?('issn') && !id['Type'].include?('locals') issns.push(id['Value']) end end end issns end |
#bib_issue ⇒ Object
786 787 788 789 790 791 792 793 794 795 796 797 |
# File 'lib/ebsco/eds/record.rb', line 786 def bib_issue if @bib_part && @bib_part.fetch('BibEntity',{}).fetch('Numbering',{}).any? item_issue = @bib_part.fetch('BibEntity',{}).fetch('Numbering',{}).find{|item| item['Type'] == 'issue'} if item_issue item_issue['Value'] else nil end else nil end end |
#bib_languages ⇒ Object
595 596 597 598 599 600 601 |
# File 'lib/ebsco/eds/record.rb', line 595 def bib_languages if @bib_entity && @bib_entity.fetch('Languages', {}).any? @bib_entity.fetch('Languages', {}).map{|lang| lang['Text']} else nil end end |
#bib_page_count ⇒ Object
def bib_pages
@bib_entity.fetch('PhysicalDescription', {})['Pagination']
end
607 608 609 610 611 612 613 |
# File 'lib/ebsco/eds/record.rb', line 607 def bib_page_count if @bib_entity @bib_entity.deep_find('PageCount').first else nil end end |
#bib_page_start ⇒ Object
615 616 617 618 619 620 621 |
# File 'lib/ebsco/eds/record.rb', line 615 def bib_page_start if @bib_entity @bib_entity.deep_find('StartPage').first else nil end end |
#bib_publication_date ⇒ Object
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 |
# File 'lib/ebsco/eds/record.rb', line 730 def bib_publication_date if @bib_part && @bib_part.fetch('BibEntity',{}).fetch('Dates',{}).any? _date = @bib_part.fetch('BibEntity',{}).fetch('Dates',{}).find{|item| item['Type'] == 'published'} if _date if _date.has_key?('Y') && _date.has_key?('M') && _date.has_key?('D') _date['Y'] + '-' + _date['M'] + '-' + _date['D'] else nil end else nil end else nil end end |
#bib_publication_month ⇒ Object
760 761 762 763 764 765 766 767 768 769 770 771 |
# File 'lib/ebsco/eds/record.rb', line 760 def bib_publication_month if @bib_part && @bib_part.fetch('BibEntity',{}).fetch('Dates',{}).any? _date = @bib_part.fetch('BibEntity',{}).fetch('Dates',{}).find{|item| item['Type'] == 'published'} if _date _date.has_key?('M') ? _date['M'] : nil else nil end else nil end end |
#bib_publication_year ⇒ Object
747 748 749 750 751 752 753 754 755 756 757 758 |
# File 'lib/ebsco/eds/record.rb', line 747 def bib_publication_year if @bib_part && @bib_part.fetch('BibEntity',{}).fetch('Dates',{}).any? _date = @bib_part.fetch('BibEntity',{}).fetch('Dates',{}).find{|item| item['Type'] == 'published'} if _date _date.has_key?('Y') ? _date['Y'] : nil else nil end else nil end end |
#bib_source_title ⇒ Object
BIB - IS PART OF (journal, book)
640 641 642 643 644 645 646 647 648 649 650 651 |
# File 'lib/ebsco/eds/record.rb', line 640 def bib_source_title if @bib_part && @bib_part.fetch('BibEntity',{}).fetch('Titles',{}).any? item_title_full = @bib_part.fetch('BibEntity',{}).fetch('Titles',{}).find{|item| item['Type'] == 'main'} if item_title_full item_title_full['TitleFull'] else nil end else nil end end |
#bib_subjects ⇒ Object
587 588 589 590 591 592 593 |
# File 'lib/ebsco/eds/record.rb', line 587 def bib_subjects if @bib_entity @bib_entity.deep_find('SubjectFull') else nil end end |
#bib_title ⇒ Object
BIB ENTITY
558 559 560 561 562 563 564 565 566 567 568 569 |
# File 'lib/ebsco/eds/record.rb', line 558 def bib_title if @bib_entity && @bib_entity.fetch('Titles', {}).any? item_bib_title = @bib_entity.fetch('Titles', {}).find{|item| item['Type'] == 'main'} if item_bib_title item_bib_title['TitleFull'] else nil end else nil end end |
#bib_volume ⇒ Object
773 774 775 776 777 778 779 780 781 782 783 784 |
# File 'lib/ebsco/eds/record.rb', line 773 def bib_volume if @bib_part && @bib_part.fetch('BibEntity',{}).fetch('Numbering',{}).any? item_volume = @bib_part.fetch('BibEntity',{}).fetch('Numbering',{}).find{|item| item['Type'] == 'volume'} if item_volume item_volume['Value'] else nil end else nil end end |
#cover_medium_url ⇒ Object
Cover image - medium size link
305 306 307 308 309 310 311 |
# File 'lib/ebsco/eds/record.rb', line 305 def cover_medium_url if images('medium').any? images('medium').first[:src] else nil end end |
#cover_thumb_url ⇒ Object
Cover image - thumbnail size link
296 297 298 299 300 301 302 |
# File 'lib/ebsco/eds/record.rb', line 296 def cover_thumb_url if images('thumb').any? images('thumb').first[:src] else nil end end |
#fulltext_link(type = 'first') ⇒ Object
The first fulltext link.
417 418 419 420 421 422 423 424 |
# File 'lib/ebsco/eds/record.rb', line 417 def fulltext_link(type = 'first') fulltext_links.each do |link| if link[:type] == type return link end end fulltext_links.first || {} end |
#fulltext_links ⇒ Object
All available fulltext links.
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 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 |
# File 'lib/ebsco/eds/record.rb', line 435 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' link_url = ebscolink['Url'] || 'detail' links.push({url: link_url, label: link_label, icon: link_icon, type: 'pdf', expires: true}) @eds_pdf_fulltext_available = true end end end # commenting out for now, not sure how 'detail' urls are useful in a blacklight context? # htmlfulltextcheck = @record.fetch('FullText',{}).fetch('Text',{}).fetch('Availability',{}) # 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' link_url = ebscolink['Url'] || 'detail' links.push({url: link_url, label: link_label, icon: link_icon, type: 'ebook-pdf', expires: true}) @eds_ebook_pdf_fulltext_available = true 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' link_url = ebscolink['Url'] || 'detail' links.push({url: link_url, label: link_label, icon: link_icon, type: 'ebook-epub', expires: true}) @eds_ebook_epub_fulltext_available = true 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] if item['Label'] link_label = item['Label'] else link_label_start = item['Data'].index('link>')+8 link_label = item['Data'][link_label_start..-1] link_label = link_label.strip end 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', expires: false}) 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' link_url = ebscolink['Url'] || 'detail' links.push({url: link_url, label: link_label, icon: link_icon, type: 'smartlinks', expires: false}) @eds_pdf_fulltext_available = true 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_url = add_protocol(link_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', expires: false}) end end links end |
#get_item_data(options) ⇒ Object
849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 |
# File 'lib/ebsco/eds/record.rb', line 849 def get_item_data() if @items.empty? nil else if [:name] and [:label] and [:group] @items.each do |item| if item['Name'] == [:name] && item['Label'] == [:label] && item['Group'] == [:group] return sanitize_data(item) end end return nil elsif [:name] and [:label] @items.each do |item| if item['Name'] == [:name] && item['Label'] == [:label] return sanitize_data(item) end end return nil elsif [:name] and [:group] @items.each do |item| if item['Name'] == [:name] && item['Group'] == [:group] return sanitize_data(item) end end return nil elsif [:label] and [:group] @items.each do |item| if item['Label'] == [:label] && item['Group'] == [:group] return sanitize_data(item) end end return nil elsif [:label] @items.each do |item| if item['Label'] == [:label] return sanitize_data(item) end end return nil elsif [:name] @items.each do |item| if item['Name'] == [:name] return sanitize_data(item) end end return nil else nil end end end |
#html_decode_and_sanitize(data, config = nil) ⇒ Object
Decode any html elements and then run it through sanitize to preserve entities (eg: ampersand) and strip out elements/attributes that aren’t explicitly whitelisted. The RELAXED config: github.com/rgrove/sanitize/blob/master/lib/sanitize/config/relaxed.rb
950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 |
# File 'lib/ebsco/eds/record.rb', line 950 def html_decode_and_sanitize(data, config = nil) default_config = Sanitize::Config.merge(Sanitize::Config::RELAXED, :elements => Sanitize::Config::RELAXED[:elements] + %w[relatesto searchlink ephtml], :attributes => Sanitize::Config::RELAXED[:attributes].merge( 'searchlink' => %w[fieldcode term])) sanitize_config = config.nil? ? default_config : config html = CGI.unescapeHTML(data.to_s) # need to double-unescape data with an ephtml section if html =~ /<ephtml>/ html = CGI.unescapeHTML(html) html = html.gsub(/\\"/, '"') html = html.gsub(/\\n /, '') end sanitized_html = Sanitize.fragment(html, sanitize_config) # sanitize 5.0 fails to restore element case after doing lowercase sanitized_html = sanitized_html.gsub(/<searchlink/, '<searchLink') sanitized_html = sanitized_html.gsub(/<\/searchlink>/, '</searchLink>') sanitized_html end |
#html_fulltext ⇒ Object
Fulltext - RETRIEVE ONLY
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
# File 'lib/ebsco/eds/record.rb', line 323 def html_fulltext if @record.fetch('FullText',{}).fetch('Text',{}).fetch('Availability',0) == '1' # sanitize? if @decode_sanitize_html # transformer clean_fulltext = lambda do |env| node = env[:node] if node.name == 'title' node.name = 'h1' end if node.name == 'sbt' node.name = 'h2' end if node.name == 'jsection' node.name = 'h3' end if node.name == 'et' node.name = 'h3' end node end fulltext_config = Sanitize::Config.merge(Sanitize::Config::RELAXED, :elements => Sanitize::Config::RELAXED[:elements] + %w[relatesto searchlink], :attributes => Sanitize::Config::RELAXED[:attributes].merge( 'searchlink' => %w[fieldcode term]), :remove_contents => true, :transformers => [clean_fulltext]) html_decode_and_sanitize(@record.fetch('FullText',{}).fetch('Text',{})['Value'], fulltext_config) else @record.fetch('FullText',{}).fetch('Text',{})['Value'] end else nil end end |
#html_fulltext_available ⇒ Object
Fulltext available
314 315 316 317 318 319 320 |
# File 'lib/ebsco/eds/record.rb', line 314 def html_fulltext_available if @record.fetch('FullText',{}).fetch('Text',{}).fetch('Availability',0) == '1' true else false end end |
#images(size_requested = 'all') ⇒ Object
List of cover images.
365 366 367 368 369 370 371 372 373 374 375 376 |
# File 'lib/ebsco/eds/record.rb', line 365 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 returned_images end |
#item_related_isbns ⇒ Object
related ISBNs
396 397 398 399 400 401 402 403 |
# File 'lib/ebsco/eds/record.rb', line 396 def isbns = get_item_data({label: 'Related ISBNs'}) if isbns isbns.split(' ').map!{|item| item.gsub(/\.$/, '')} else nil end end |
#non_fulltext_links ⇒ Object
All available non-fulltext links.
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 |
# File 'lib/ebsco/eds/record.rb', line 538 def non_fulltext_links links = [] other_customlinks = @record.fetch('CustomLinks',{}) if other_customlinks.count > 0 other_customlinks.each do |other_customlink| link_url = other_customlink['Url'] link_url = add_protocol(link_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', expires: false}) end end links end |
#quick_view_images ⇒ Object
List of image quick view
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
# File 'lib/ebsco/eds/record.rb', line 379 def quick_view_images returned_images = [] images = @record.fetch('ImageQuickViewItems', {}) if images.count > 0 images.each do |quick_view_item| image_id = quick_view_item['DbId'] image_accession = quick_view_item['An'] image_type = quick_view_item['Type'] # todo: change to https, large/small url? image_url = quick_view_item['Url'] returned_images.push({url: image_url, id: image_id, accession_number: image_accession, type: image_type}) end end returned_images end |
#require_sanitize ⇒ Object
1016 1017 1018 1019 1020 |
# File 'lib/ebsco/eds/record.rb', line 1016 def require_sanitize require 'sanitize' rescue Gem::LoadError, LoadError raise EBSCO::EDS::MissingDependency.new 'Sanitize is turned on, but the sanitize gem is not loaded' end |
#retrieve_options ⇒ Object
Options hash containing accession number and database ID. This can be passed to the retrieve method.
271 272 273 274 275 276 |
# File 'lib/ebsco/eds/record.rb', line 271 def = {} ['an'] = @eds_accession_number ['dbid'] = @eds_database_id end |
#sanitize_data(item) ⇒ Object
decode & sanitize html tags found in item data; apply any special transformations
917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 |
# File 'lib/ebsco/eds/record.rb', line 917 def sanitize_data(item) if item['Data'] data = item['Data'] # group-specific transformations if item['Group'] group = item['Group'] if group == 'Su' data = add_subject_searchlinks(data) # translate searchLink field codes to DE? if @all_subjects_search_links data = data.gsub(/(searchLink fieldCode=")([A-Z]+)/, '\1DE') end end end # decode-sanitize? if @decode_sanitize_html data = html_decode_and_sanitize(data) end data else nil # no item data present end end |
#set_citation_exports(val) ⇒ Object
991 992 993 |
# File 'lib/ebsco/eds/record.rb', line 991 def set_citation_exports(val) @eds_citation_exports = val end |
#set_citation_styles(val) ⇒ Object
995 996 997 |
# File 'lib/ebsco/eds/record.rb', line 995 def set_citation_styles(val) @eds_citation_styles = val end |
#source_title ⇒ Object
The source title (example: ‘Salem Press Encyclopedia’)
289 290 291 292 293 |
# File 'lib/ebsco/eds/record.rb', line 289 def source_title _retval = bib_source_title || get_item_data({name: 'TitleSource'}) _reval = nil? if _retval == title # suppress if it's identical to title _retval.nil?? nil : _retval end |
#title ⇒ Object
The title.
279 280 281 282 283 284 285 286 |
# File 'lib/ebsco/eds/record.rb', line 279 def title _retval = bib_title || get_item_data({name: 'Title'}) # TODO: make this configurable if _retval.nil? _retval = 'This title is unavailable for guests, please login to see more information.' end _retval end |
#to_attr_hash ⇒ Object
799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 |
# File 'lib/ebsco/eds/record.rb', line 799 def to_attr_hash hash = Hash.new instance_variables.each do |var| if var != :@record && var != :@items && var != :@bib_entity && var != :@bib_part && var != :@bib_relationships && var != :@image_quick_view_items && var != :@eds_citation_exports && var != :@eds_citation_styles hash[var.to_s.sub(/^@/, '')] = instance_variable_get(var) end end if all_links hash['eds_fulltext_link'] = { 'id' => @eds_database_id + '__' + @eds_accession_number, 'links' => all_links } end # add citation styles and exports unless @eds_citation_exports.nil? hash['eds_citation_exports'] = @eds_citation_exports.items end unless @eds_citation_styles.nil? hash['eds_citation_styles'] = @eds_citation_styles.items end hash end |
#to_solr ⇒ Object
830 831 832 833 834 835 836 837 838 839 840 841 842 |
# File 'lib/ebsco/eds/record.rb', line 830 def to_solr item_hash = to_attr_hash { 'responseHeader' => { 'status' => 0 }, 'response' => { 'numFound' => 1, 'start' => 0, 'docs' => [item_hash] } } end |