Module: Blacklight::Marc::DocumentExport
- Included in:
- DocumentExtension
- Defined in:
- app/models/concerns/blacklight/marc/document_export.rb
Overview
Written for use with Blacklight::Marc::DocumentExtension, but you can use it for your own custom Blacklight document Marc extension too – just include this module in any document extension (or any other class) that provides a #to_marc returning a ruby-marc object. This module will add in export_as translation methods for a variety of formats.
Class Method Summary collapse
Instance Method Summary collapse
-
#export_as_apa_citation_txt ⇒ Object
TODO This exporting as formatted citation thing should be re-thought redesigned at some point to be more general purpose, but this is in-line with what we had before, but at least now attached to the document extension where it belongs.
- #export_as_chicago_citation_txt ⇒ Object
-
#export_as_endnote ⇒ Object
Endnote Import Format.
- #export_as_marc ⇒ Object
- #export_as_marcxml ⇒ Object (also: #export_as_xml)
- #export_as_mla_citation_txt ⇒ Object
-
#export_as_openurl_ctx_kev(format = nil) ⇒ Object
Exports as an OpenURL KEV (key-encoded value) query string.
-
#export_as_refworks_marc_txt ⇒ Object
This format used to be called ‘refworks’, which wasn’t really accurate, sounds more like ‘refworks tagged format’.
Class Method Details
.register_export_formats(document) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'app/models/concerns/blacklight/marc/document_export.rb', line 11 def self.register_export_formats(document) document.will_export_as(:xml) document.will_export_as(:marc, "application/marc") # marcxml content type: # http://tools.ietf.org/html/draft-denenberg-mods-etc-media-types-00 document.will_export_as(:marcxml, "application/marcxml+xml") document.will_export_as(:openurl_ctx_kev, "application/x-openurl-ctx-kev") document.will_export_as(:refworks_marc_txt, "text/plain") document.will_export_as(:endnote, "application/x-endnote-refer") end |
Instance Method Details
#export_as_apa_citation_txt ⇒ Object
TODO This exporting as formatted citation thing should be re-thought redesigned at some point to be more general purpose, but this is in-line with what we had before, but at least now attached to the document extension where it belongs.
37 38 39 |
# File 'app/models/concerns/blacklight/marc/document_export.rb', line 37 def export_as_apa_citation_txt apa_citation( to_marc ) end |
#export_as_chicago_citation_txt ⇒ Object
45 46 47 |
# File 'app/models/concerns/blacklight/marc/document_export.rb', line 45 def export_as_chicago_citation_txt chicago_citation( to_marc ) end |
#export_as_endnote ⇒ Object
Endnote Import Format. See the EndNote User Guide at: www.endnote.com/support/enx3man-terms-win.asp Chapter 7: Importing Reference Data into EndNote / Creating a Tagged “EndNote Import” File
Note: This code is copied from what used to be in the previous version in ApplicationHelper#render_to_endnote. It does NOT produce very good endnote import format; the %0 is likely to be entirely illegal, the rest of the data is barely correct but messy. TODO, a new version of this, or better yet just an export_as_ris instead, which will be more general purpose.
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 |
# File 'app/models/concerns/blacklight/marc/document_export.rb', line 143 def export_as_endnote() end_note_format = { "%A" => "100.a", "%C" => "260.a", "%D" => "260.c", "%E" => "700.a", "%I" => "260.b", "%J" => "440.a", "%@" => "020.a", "%_@" => "022.a", "%T" => "245.a,245.b", "%U" => "856.u", "%7" => "250.a" } marc_obj = to_marc return unless marc_obj # TODO. This should be rewritten to guess # from actual Marc instead, probably. format_str = 'Generic' text = '' text << "%0 #{ format_str }\n" # If there is some reliable way of getting the language of a record we can add it here #text << "%G #{record['language'].first}\n" end_note_format.each do |key,value| values = value.split(",") first_value = values[0].split('.') if values.length > 1 second_value = values[1].split('.') else second_value = [] end if marc_obj[first_value[0].to_s] marc_obj.find_all{|f| (first_value[0].to_s) === f.tag}.each do |field| if field[first_value[1]].to_s or field[second_value[1]].to_s text << "#{key.gsub('_','')}" if field[first_value[1]].to_s text << " #{field[first_value[1]].to_s}" end if field[second_value[1]].to_s text << " #{field[second_value[1]].to_s}" end text << "\n" end end end end text end |
#export_as_marc ⇒ Object
23 24 25 |
# File 'app/models/concerns/blacklight/marc/document_export.rb', line 23 def export_as_marc to_marc.to_marc end |
#export_as_marcxml ⇒ Object Also known as: export_as_xml
27 28 29 |
# File 'app/models/concerns/blacklight/marc/document_export.rb', line 27 def export_as_marcxml to_marc.to_xml.to_s end |
#export_as_mla_citation_txt ⇒ Object
41 42 43 |
# File 'app/models/concerns/blacklight/marc/document_export.rb', line 41 def export_as_mla_citation_txt mla_citation( to_marc ) end |
#export_as_openurl_ctx_kev(format = nil) ⇒ Object
Exports as an OpenURL KEV (key-encoded value) query string. For use to create COinS, among other things. COinS are for Zotero, among other things. TODO: This is wierd and fragile code, it should use ruby OpenURL gem instead to work a lot more sensibly. The “format” argument was in the old marc.marc.to_zotero call, but didn’t neccesarily do what it thought it did anyway. Left in for now for backwards compatibilty, but should be replaced by just ruby OpenURL.
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 98 99 |
# File 'app/models/concerns/blacklight/marc/document_export.rb', line 57 def export_as_openurl_ctx_kev(format = nil) title = to_marc.find{|field| field.tag == '245'} = to_marc.find{|field| field.tag == '100'} = to_marc.find{|field| field.tag == '110'} publisher_info = to_marc.find{|field| field.tag == '260'} edition = to_marc.find{|field| field.tag == '250'} isbn = to_marc.find{|field| field.tag == '020'} issn = to_marc.find{|field| field.tag == '022'} format = format.first if format.is_a?(Array) format = format.downcase.strip unless format.nil? export_text = "" if format == 'book' export_text << "ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rfr_id=info%3Asid%2Fblacklight.rubyforge.org%3Agenerator&rft.genre=book&" export_text << "rft.btitle=#{(title.nil? or title['a'].nil?) ? "" : CGI::escape(title['a'])}+#{(title.nil? or title['b'].nil?) ? "" : CGI::escape(title['b'])}&" export_text << "rft.title=#{(title.nil? or title['a'].nil?) ? "" : CGI::escape(title['a'])}+#{(title.nil? or title['b'].nil?) ? "" : CGI::escape(title['b'])}&" export_text << "rft.au=#{(.nil? or ['a'].nil?) ? "" : CGI::escape(['a'])}&" export_text << "rft.aucorp=#{CGI::escape(['a']) if ['a']}+#{CGI::escape(['b']) if ['b']}&" unless .blank? export_text << "rft.date=#{(publisher_info.nil? or publisher_info['c'].nil?) ? "" : CGI::escape(publisher_info['c'])}&" export_text << "rft.place=#{(publisher_info.nil? or publisher_info['a'].nil?) ? "" : CGI::escape(publisher_info['a'])}&" export_text << "rft.pub=#{(publisher_info.nil? or publisher_info['b'].nil?) ? "" : CGI::escape(publisher_info['b'])}&" export_text << "rft.edition=#{(edition.nil? or edition['a'].nil?) ? "" : CGI::escape(edition['a'])}&" export_text << "rft.isbn=#{(isbn.nil? or isbn['a'].nil?) ? "" : isbn['a']}" elsif (format =~ /journal/i) # checking using include because institutions may use formats like Journal or Journal/Magazine export_text << "ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rfr_id=info%3Asid%2Fblacklight.rubyforge.org%3Agenerator&rft.genre=article&" export_text << "rft.title=#{(title.nil? or title['a'].nil?) ? "" : CGI::escape(title['a'])}+#{(title.nil? or title['b'].nil?) ? "" : CGI::escape(title['b'])}&" export_text << "rft.atitle=#{(title.nil? or title['a'].nil?) ? "" : CGI::escape(title['a'])}+#{(title.nil? or title['b'].nil?) ? "" : CGI::escape(title['b'])}&" export_text << "rft.aucorp=#{CGI::escape(['a']) if ['a']}+#{CGI::escape(['b']) if ['b']}&" unless .blank? export_text << "rft.date=#{(publisher_info.nil? or publisher_info['c'].nil?) ? "" : CGI::escape(publisher_info['c'])}&" export_text << "rft.issn=#{(issn.nil? or issn['a'].nil?) ? "" : issn['a']}" else export_text << "ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Adc&rfr_id=info%3Asid%2Fblacklight.rubyforge.org%3Agenerator&" export_text << "rft.title=" + ((title.nil? or title['a'].nil?) ? "" : CGI::escape(title['a'])) export_text << ((title.nil? or title['b'].nil?) ? "" : CGI.escape(" ") + CGI::escape(title['b'])) export_text << "&rft.creator=" + ((.nil? or ['a'].nil?) ? "" : CGI::escape(['a'])) export_text << "&rft.aucorp=#{CGI::escape(['a']) if ['a']}+#{CGI::escape(['b']) if ['b']}" unless .blank? export_text << "&rft.date=" + ((publisher_info.nil? or publisher_info['c'].nil?) ? "" : CGI::escape(publisher_info['c'])) export_text << "&rft.place=" + ((publisher_info.nil? or publisher_info['a'].nil?) ? "" : CGI::escape(publisher_info['a'])) export_text << "&rft.pub=" + ((publisher_info.nil? or publisher_info['b'].nil?) ? "" : CGI::escape(publisher_info['b'])) export_text << "&rft.format=" + (format.nil? ? "" : CGI::escape(format)) end export_text.html_safe unless export_text.blank? end |
#export_as_refworks_marc_txt ⇒ Object
This format used to be called ‘refworks’, which wasn’t really accurate, sounds more like ‘refworks tagged format’. Which this is not, it’s instead some weird under-documented Refworks proprietary marc-ish in text/plain format. See robotlibrarian.billdueber.com/2009/05/sending-marcish-data-to-refworks/
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'app/models/concerns/blacklight/marc/document_export.rb', line 107 def export_as_refworks_marc_txt marc_obj = to_marc return unless marc_obj fields = marc_obj.find_all { |f| ('000'..'999') === f.tag } text = "LEADER #{to_marc.leader}" fields.each do |field| unless ["940","999"].include?(field.tag) if field.is_a?(MARC::ControlField) text << "#{field.tag} #{field.value}\n" else text << "#{field.tag} " text << (field.indicator1 ? field.indicator1 : " ") text << (field.indicator2 ? field.indicator2 : " ") text << " " field.each {|s| s.code == 'a' ? text << "#{s.value}" : text << " |#{s.code}#{s.value}"} text << "\n" end end end # As of 11 May 2010, Refworks has a problem with UTF-8 if it's decomposed, # it seems to want C form normalization, although RefWorks support # couldn't tell me that. -jrochkind text.unicode_normalize(:nfc) end |