Method: Referent#to_citation
- Defined in:
- app/models/referent.rb
#to_citation ⇒ Object
Creates a hash for use in View code to display a citation
TODO, move to_citation, type_of_thing, and container_type_of_thing OUT of Refernet, to helper module or own class.
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 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 |
# File 'app/models/referent.rb', line 282 def to_citation citation = {} # call self.metadata once and use the array for efficiency, don't # keep calling it. profiling shows it DOES make a difference. = self. if ['atitle'].present? citation[:title] = ['atitle'] ['title','btitle','jtitle'].each do | t_type | if [t_type].present? citation[:container_title] = [t_type] break end end else # only top-level thing, no sub-thing ['title','btitle','jtitle'].each do | t_type | if [t_type].present? citation[:title] = [t_type] break end end end citation[:title_label] = I18n.t("umlaut.citation.title_of_x", :x => self.type_of_thing, :default => "umlaut.citation.title_label") citation[:container_label] = self.container_type_of_thing # add publisher for books if (['genre'] =~ /book/i) citation[:pub] = ['pub'] unless ['pub'].blank? end citation[:issn] = issn if issn citation[:isbn] = isbn if isbn ['volume','issue','date'].each do | key | citation[key.to_sym] = [key] end if ["au"].present? citation[:author] = ["au"].strip elsif ["aulast"] citation[:author] = ["aulast"].strip if ["aufirst"].present? citation[:author] += ', '+["aufirst"].strip else if ["auinit"].present? citation[:author] += ', '+["auinit"].strip else if ["auinit1"].present? citation[:author] += ', '+["auinit1"].strip end if ["auinitm"].present? citation[:author] += ["auinitm"].strip end end end elsif ["aucorp"] citation[:author] = ["aucorp"] end if ['spage'] citation[:page] = ['spage'] citation[:page] += ' - ' + ['epage'] if ! ['epage'].blank? end citation[:identifiers] = [] self.identifiers.each do | id | citation[:identifiers] << id unless (id.blank? || id.match(/^tag:/)) end return citation end |