Module: Blacklight::Solr::Document::MarcExport
- Included in:
- Marc
- Defined in:
- vendor/plugins/blacklight/lib/blacklight/solr/document/marc_export.rb
Overview
Written for use with Blacklight::Solr::Document::Marc, 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)
-
- (Object) export_as_apa_citation_txt
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.
-
- (Object) export_as_endnote
Endnote Import Format.
- - (Object) export_as_marc
- - (Object) export_as_marcxml (also: #export_as_xml)
- - (Object) export_as_mla_citation_txt
-
- (Object) export_as_openurl_ctx_kev(format = nil)
Exports as an OpenURL KEV (key-encoded value) query string.
-
- (Object) export_as_refworks_marc_txt
This format used to be called ‘refworks’, which wasn’t really accurate, sounds more like ‘refworks tagged format’.
- - (Object) to_apa
- - (Object) to_mla
-
- (Object) to_zotero(format)
DEPRECATED stuff left in for backwards compatibility, but should be gotten rid of eventually.
Class Method Details
+ (Object) register_export_formats(document)
8 9 10 11 12 13 14 15 16 17 |
# File 'vendor/plugins/blacklight/lib/blacklight/solr/document/marc_export.rb', line 8 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
- (Object) export_as_apa_citation_txt
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.
34 35 36 |
# File 'vendor/plugins/blacklight/lib/blacklight/solr/document/marc_export.rb', line 34 def export_as_apa_citation_txt apa_citation( to_marc ) end |
- (Object) export_as_endnote
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.
121 122 123 124 125 126 127 128 129 130 131 132 133 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 |
# File 'vendor/plugins/blacklight/lib/blacklight/solr/document/marc_export.rb', line 121 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 # TODO. This was inherited functionality (although refactored), # but it wasn't actually clear that :display_type would # be used this way. This should be rewritten to guess # from actual Marc instead, probably. format_str = Blacklight.config[:show][:display_type] format_str = format_str[0] if format_str.kind_of?(Array) format_str = format_str.titlecase 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 |
- (Object) export_as_marc
20 21 22 |
# File 'vendor/plugins/blacklight/lib/blacklight/solr/document/marc_export.rb', line 20 def export_as_marc to_marc.to_marc end |
- (Object) export_as_marcxml Also known as: export_as_xml
24 25 26 |
# File 'vendor/plugins/blacklight/lib/blacklight/solr/document/marc_export.rb', line 24 def export_as_marcxml to_marc.to_xml.to_s end |
- (Object) export_as_mla_citation_txt
38 39 40 |
# File 'vendor/plugins/blacklight/lib/blacklight/solr/document/marc_export.rb', line 38 def export_as_mla_citation_txt mla_citation( to_marc ) end |
- (Object) export_as_openurl_ctx_kev(format = nil)
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.
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 |
# File 'vendor/plugins/blacklight/lib/blacklight/solr/document/marc_export.rb', line 50 def export_as_openurl_ctx_kev(format = nil) title = to_marc.find{|field| field.tag == '245'} = to_marc.find{|field| field.tag == '100'} 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'} unless format.nil? format.is_a?(Array) ? format = format[0].downcase.strip : format = format.downcase.strip end if format == 'book' return "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&rft.btitle=#{(title.nil? or title['a'].nil?) ? "" : CGI::escape(title['a'])}+#{(title.nil? or title['b'].nil?) ? "" : CGI::escape(title['b'])}&rft.title=#{(title.nil? or title['a'].nil?) ? "" : CGI::escape(title['a'])}+#{(title.nil? or title['b'].nil?) ? "" : CGI::escape(title['b'])}&rft.au=#{(author.nil? or author['a'].nil?) ? "" : CGI::escape(author['a'])}&rft.date=#{(publisher_info.nil? or publisher_info['c'].nil?) ? "" : CGI::escape(publisher_info['c'])}&rft.pub=#{(publisher_info.nil? or publisher_info['a'].nil?) ? "" : CGI::escape(publisher_info['a'])}&rft.edition=#{(edition.nil? or edition['a'].nil?) ? "" : CGI::escape(edition['a'])}&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 return "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&rft.title=#{(title.nil? or title['a'].nil?) ? "" : CGI::escape(title['a'])}+#{(title.nil? or title['b'].nil?) ? "" : CGI::escape(title['b'])}&rft.atitle=#{(title.nil? or title['a'].nil?) ? "" : CGI::escape(title['a'])}+#{(title.nil? or title['b'].nil?) ? "" : CGI::escape(title['b'])}&rft.date=#{(publisher_info.nil? or publisher_info['c'].nil?) ? "" : CGI::escape(publisher_info['c'])}&rft.issn=#{(issn.nil? or issn['a'].nil?) ? "" : issn['a']}" else value = "" value += "ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Adc&rfr_id=info%3Asid%2Fblacklight.rubyforge.org%3Agenerator&" value += "rft.title=" + ((title.nil? or title['a'].nil?) ? "" : CGI::escape(title['a'])) value += ((title.nil? or title['b'].nil?) ? "" : CGI.escape(" ") + CGI::escape(title['b'])) value += "&rft.creator=" + ((.nil? or ['a'].nil?) ? "" : CGI::escape(['a'])) value += "&rft.date=" + ((publisher_info.nil? or publisher_info['c'].nil?) ? "" : CGI::escape(publisher_info['c'])) value += "&rft.pub=" + ((publisher_info.nil? or publisher_info['a'].nil?) ? "" : CGI::escape(publisher_info['a'])) value += "&rft.format=" + (format.nil? ? "" : CGI::escape(format)) return value end end |
- (Object) export_as_refworks_marc_txt
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/sending-marcish-data-to-refworks/
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'vendor/plugins/blacklight/lib/blacklight/solr/document/marc_export.rb', line 84 def export_as_refworks_marc_txt # plugin/gem weirdness means we do need to manually require # here. # 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 require 'unicode' fields = to_marc.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 Unicode.normalize_C(text) end |
- (Object) to_apa
184 185 186 187 |
# File 'vendor/plugins/blacklight/lib/blacklight/solr/document/marc_export.rb', line 184 def to_apa warn("[DEPRECATION] Call document.export_as_apa_citation instead.") export_as_apa_citation end |
- (Object) to_mla
189 190 191 |
# File 'vendor/plugins/blacklight/lib/blacklight/solr/document/marc_export.rb', line 189 def to_mla warn("[DEPRECATION] Call document.export_as_mla_citation instead.") end |
- (Object) to_zotero(format)
DEPRECATED stuff left in for backwards compatibility, but should be gotten rid of eventually.
179 180 181 182 |
# File 'vendor/plugins/blacklight/lib/blacklight/solr/document/marc_export.rb', line 179 def to_zotero(format) warn("[DEPRECATION] Simply call document.export_as_openurl_kev to get an openURL kev context object suitable for including in a COinS; then have view code make the span for the COinS. ") "<span class=\"Z3988\" title=\"#{export_as_openurl_kev(format)}\"></span>" end |