Class: BentoSearch::OpenurlCreator
- Inherits:
-
Object
- Object
- BentoSearch::OpenurlCreator
- Includes:
- ActionView::Helpers::SanitizeHelper
- Defined in:
- app/models/bento_search/openurl_creator.rb
Overview
Helper class used to take a ResultItem, and construct a ruby OpenURL::ContextObject out of it. That represents a NISO Z39.88 OpenURL context object, useful for using with linking software that expects such. en.wikipedia.org/wiki/OpenURL
co = OpenurlCreator.new( decorated_result_item ).to_open_url
# => ruby OpenURL::ContextObject object.
co.kev
# => context object serialized to KEV format (URL query string)
In some cases nil can be returned, if no reasonable OpenURL can be created from the ResultItem.
Instance Attribute Summary collapse
-
#result_item ⇒ Object
Returns the value of attribute result_item.
Instance Method Summary collapse
-
#ensure_no_tags(str) ⇒ Object
If the input is not marked html_safe?, just return it.
-
#format ⇒ Object
We need to map from our formats to which OpenURL ‘format’ we’re going to create.
-
#genre ⇒ Object
rft.genre value.
-
#initialize(ri) ⇒ OpenurlCreator
constructor
Pass in a DECORATED result_item, eg StandardDecorator.new(result_item, nil) Need the display logic methods in the decorator, not just a raw result_item.
- #to_openurl ⇒ Object
Constructor Details
#initialize(ri) ⇒ OpenurlCreator
Pass in a DECORATED result_item, eg StandardDecorator.new(result_item, nil) Need the display logic methods in the decorator, not just a raw result_item.
28 29 30 |
# File 'app/models/bento_search/openurl_creator.rb', line 28 def initialize(ri) self.result_item = ri end |
Instance Attribute Details
#result_item ⇒ Object
Returns the value of attribute result_item.
23 24 25 |
# File 'app/models/bento_search/openurl_creator.rb', line 23 def result_item @result_item end |
Instance Method Details
#ensure_no_tags(str) ⇒ Object
If the input is not marked html_safe?, just return it. Otherwise strip html tags from it AND replace HTML char entities
156 157 158 159 160 161 162 163 164 165 |
# File 'app/models/bento_search/openurl_creator.rb', line 156 def (str) return str unless str.html_safe? str = str.to_str # get it out of HTMLSafeBuffer, which messes things up str = (str) str = HTMLEntities.new.decode(str) return str end |
#format ⇒ Object
We need to map from our formats to which OpenURL ‘format’ we’re going to create.
We only pick from a limited set of standard scholarly citation formats, that’s all any actual widespread software recognizes.
Returns the last component of a valid format from: alcme.oclc.org/openurl/servlet/OAIHandler?verb=ListRecords&metadataPrefix=oai_dc&set=Core:Metadata+Formats
Eg, “book”, “journal”, “dissertation”.
In fact, we only pick from one of those three – by default, if we can’t figure out exactly what it is or can’t map it to a specific format, we’ll return ‘journal’, never nil. ‘journal’ serves, in practice, with much actual software, as a neutral default.
142 143 144 145 146 147 148 149 150 151 |
# File 'app/models/bento_search/openurl_creator.rb', line 142 def format case result_item.format when "Book", :book_item "book" when :dissertation "dissertation" else "journal" end end |
#genre ⇒ Object
rft.genre value. Yeah, the legal ones differ depending on openurl ‘format’, but we’ve given up trying to do things strictly legal, OpenURL is a bear, we do things as generally used and good enough.
can be nil.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'app/models/bento_search/openurl_creator.rb', line 105 def genre case result_item.format when "Book" "book" when :book_item "bookitem" when :conference_paper "proceeding" when :conference_proceedings "conference" when :report "report" when :serial "journal" when "Article" "article" else nil end end |
#to_openurl ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/models/bento_search/openurl_creator.rb', line 32 def to_openurl # If we have a pre-constructed KEV, just use it. if result_item.openurl_kev_co return OpenURL::ContextObject.new_from_kev( result_item.openurl_kev_co ) end context_object = OpenURL::ContextObject.new r = context_object.referent r.set_format( self.format ) if result_item.doi r.add_identifier("info:doi/#{result_item.doi}") end if result_item.pmid r.add_identifier("info:pmid/#{result_item.pmid}") end if result_item.oclcnum r.add_identifier("info:oclcnum/#{result_item.oclcnum}") # and do the one that's not actually legal practice, but is common r.("oclcnum", result_item.oclcnum) end r.("genre", self.genre) if result_item..length > 0 r.("aufirst", (result_item..first.first)) r.("aulast", (result_item..first.last)) r.("au", result_item.( result_item..first)) end if result_item.publication_date r.("date", result_item.publication_date.iso8601) else r.("date", result_item.year.to_s) end r.("volume", result_item.volume.to_s) r.("issue", result_item.issue.to_s) r.("spage", result_item.start_page.to_s) r.("epage", result_item.end_page.to_s) r.("jtitle", (result_item.source_title)) r.("issn", result_item.issn) r.("isbn", result_item.isbn) r.("pub", (result_item.publisher)) case result_item.format when "Book" r.("btitle", (result_item.complete_title)) when :book_item r.("btitle", result_item.source_title) r.("atitle", result_item.title) when "Article", :conference_paper r.("atitle", (result_item.complete_title)) else r.("title", (result_item.complete_title)) end return context_object end |