Module: Sufia::GenericFile::Export
- Included in:
- Sufia::GenericFile
- Defined in:
- app/models/concerns/sufia/generic_file/export.rb
Instance Method Summary collapse
- #export_as_apa_citation ⇒ Object
- #export_as_chicago_citation ⇒ Object
-
#export_as_endnote ⇒ Object
MIME: ‘application/x-endnote-refer’.
- #export_as_mla_citation ⇒ Object
-
#export_as_openurl_ctx_kev ⇒ Object
MIME type: ‘application/x-openurl-ctx-kev’.
- #persistent_url ⇒ Object
Instance Method Details
#export_as_apa_citation ⇒ Object
77 78 79 80 81 82 83 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 110 111 112 113 114 115 116 |
# File 'app/models/concerns/sufia/generic_file/export.rb', line 77 def export_as_apa_citation text = '' = [] = [] # setup formatted author list = .each do || next if .blank? .push(abbreviate_name()) end .each do || if == .first # first .push(.strip) elsif == .last # last .push(", & " + .strip) else # all others .push(", " + .strip) end end text << .join unless text.blank? if text[-1, 1] != "." text << ". " else text << " " end end # Get Pub Date text << "(" + setup_pub_date + "). " unless setup_pub_date.nil? # setup title info title_info = setup_title_info text << "<i>" + title_info + "</i> " unless title_info.nil? # Publisher info text << setup_pub_info unless setup_pub_info.nil? text += "." if text[-1, 1] != "." unless text.blank? text.html_safe end |
#export_as_chicago_citation ⇒ Object
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 |
# File 'app/models/concerns/sufia/generic_file/export.rb', line 159 def export_as_chicago_citation = "" = unless .blank? if .length > 10 .each_with_index do |, index| if index < 7 if index == 0 << "#{author}" if .ends_with?(",") << " " else << ", " end else << "#{name_reverse(author)}, " end end end << " et al." elsif .length > 1 .each_with_index do |, index| if index == 0 << "#{author}" if .ends_with?(",") << " " else << ", " end elsif index + 1 == .length << "and #{name_reverse(author)}." else << "#{name_reverse(author)}, " end end else << .first end end title_info = "" title_info << citation_title(clean_end_punctuation(CGI.escapeHTML(title.first)).strip) unless title.blank? pub_info = "" place = based_near.first publisher = self.publisher.first unless place.blank? place = CGI.escapeHTML(place) pub_info << place pub_info << ": " unless publisher.blank? end unless publisher.blank? publisher = CGI.escapeHTML(publisher) pub_info << publisher pub_info << ", " unless setup_pub_date.nil? end pub_info << setup_pub_date unless setup_pub_date.nil? citation = "" citation << "#{author_text} " unless .blank? citation << "<i>#{title_info}.</i> " unless title_info.blank? citation << "#{pub_info}." unless pub_info.blank? citation.html_safe end |
#export_as_endnote ⇒ Object
MIME: ‘application/x-endnote-refer’
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/models/concerns/sufia/generic_file/export.rb', line 5 def export_as_endnote end_note_format = { '%T' => [:title, ->(x) { x.first }], '%Q' => [:title, ->(x) { x.drop(1) }], '%A' => [:creator], '%C' => [:publication_place], '%D' => [:date_created], '%8' => [:date_uploaded], '%E' => [:contributor], '%I' => [:publisher], '%J' => [:series_title], '%@' => [:isbn], '%U' => [:related_url], '%7' => [:edition_statement], '%R' => [:persistent_url], '%X' => [:description], '%G' => [:language], '%[' => [:date_modified], '%9' => [:resource_type], '%~' => I18n.t('sufia.product_name'), '%W' => I18n.t('sufia.institution_name') } text = [] text << "%0 GenericFile" end_note_format.each do |endnote_key, mapping| if mapping.is_a? String values = [mapping] else values = send(mapping[0]) if self.respond_to? mapping[0] values = mapping[1].call(values) if mapping.length == 2 values = Array(values) end next if values.empty? || values.first.nil? spaced_values = values.join("; ") text << "#{endnote_key} #{spaced_values}" end text.join("\n") end |
#export_as_mla_citation ⇒ Object
118 119 120 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 |
# File 'app/models/concerns/sufia/generic_file/export.rb', line 118 def export_as_mla_citation text = '' = [] # setup formatted author list = if .length < 4 .each do || if == .first # first .push() elsif == .last # last .push(", and " + name_reverse() + ".") else # all others .push(", " + name_reverse()) end end text << .join unless text.blank? if text[-1, 1] != "." text << ". " else text << " " end end else text << .first + ", et al. " end # setup title title_info = setup_title_info text << "<i>" + mla_citation_title(title_info) + "</i> " unless title.blank? # Publication text << setup_pub_info + ", " unless setup_pub_info.nil? # Get Pub Date text << setup_pub_date unless setup_pub_date.nil? text << "." unless text.blank? if text[-1, 1] != "." text.html_safe end |
#export_as_openurl_ctx_kev ⇒ Object
MIME type: ‘application/x-openurl-ctx-kev’
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 |
# File 'app/models/concerns/sufia/generic_file/export.rb', line 49 def export_as_openurl_ctx_kev export_text = [] export_text << "url_ver=Z39.88-2004&ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Adc&rfr_id=info%3Asid%2Fblacklight.rubyforge.org%3Agenerator" field_map = { title: 'title', creator: 'creator', subject: 'subject', description: 'description', publisher: 'publisher', contributor: 'contributor', date_created: 'date', resource_type: 'format', identifier: 'identifier', language: 'language', tag: 'relation', based_near: 'coverage', rights: 'rights' } field_map.each do |element, kev| values = send(element) next if values.empty? || values.first.nil? values.each do |value| export_text << "rft.#{kev}=#{CGI.escape(value.to_s)}" end end export_text.join('&') unless export_text.blank? end |
#persistent_url ⇒ Object
44 45 46 |
# File 'app/models/concerns/sufia/generic_file/export.rb', line 44 def persistent_url "#{Sufia.config.persistent_hostpath}#{id}" end |