Skip to content

Commit 5489256

Browse files
authored
Merge pull request #2408 from seek4science/extended-publication-type
Extend publication type list
2 parents d1a92f7 + 109393a commit 5489256

File tree

12 files changed

+612
-208
lines changed

12 files changed

+612
-208
lines changed

app/models/publication.rb

Lines changed: 18 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def extract_bibtex_metadata(bibtex_record)
248248
month = bibtex_record[:month].try(:to_s)
249249
year = bibtex_record[:year].try(:to_s)
250250
self.published_date = Date.new(bibtex_record.year.try(:to_i) || 1, bibtex_record.month_numeric || 1, bibtex_record[:day].try(:to_i) || 1)
251-
self.published_date = nil if self.published_date.to_s == "0001-01-01"
251+
self.published_date = nil if self.published_date.to_s == '0001-01-01'
252252
self.doi = bibtex_record[:doi].try(:to_s)
253253
self.pubmed_id = bibtex_record[:pubmed_id].try(:to_s)
254254
self.booktitle = bibtex_record[:booktitle].try(:to_s)
@@ -326,7 +326,7 @@ def generate_citation(bibtex_record)
326326
self.citation = ''
327327
month = bibtex_record[:month].try(:to_s)
328328
year = bibtex_record[:year].try(:to_s)
329-
page_or_pages = (bibtex_record[:pages].try(:to_s).match?(/[^0-9]/) ? "pp." : "p." ) unless bibtex_record[:pages].nil?
329+
page_or_pages = (bibtex_record[:pages].try(:to_s).match?(/[^0-9]/) ? 'pp.' : 'p.' ) unless bibtex_record[:pages].nil?
330330
pages = bibtex_record[:pages].try(:to_s)
331331
volume = bibtex_record[:volume].try(:to_s)
332332
series = bibtex_record[:series].try(:to_s)
@@ -344,25 +344,16 @@ def generate_citation(bibtex_record)
344344
url = parse_bibtex_url(bibtex_record).try(:to_s)
345345
publication_type = PublicationType.find(self.publication_type_id)
346346

347-
if publication_type.is_journal?
347+
case publication_type.key
348+
when publication_type.journalarticle?
348349
self.citation += self.journal.nil? ? '':self.journal
349350
self.citation += volume.blank? ? '': " #{volume}"
350351
self.citation += number.nil? ? '' : "(#{number})"
351352
self.citation += pages.blank? ? '' : (":#{pages}")
352-
=begin
353-
unless year.nil?
354-
self.citation += year.nil? ? '' : (' '+year)
355-
end
356-
=end
357-
elsif publication_type.is_booklet?
353+
when publication_type.booklet?
358354
self.citation += howpublished.blank? ? '': "#{howpublished}"
359355
self.citation += address.nil? ? '' : (", #{address}")
360-
=begin
361-
unless year.nil?
362-
self.citation += year.nil? ? '' : (' '+year)
363-
end
364-
=end
365-
elsif publication_type.is_inbook?
356+
when publication_type.bookchapter?
366357
self.citation += self.booktitle.nil? ? '' : ("In #{self.booktitle}")
367358
self.citation += volume.blank? ? '' : (", volume #{volume}")
368359
self.citation += series.blank? ? '' : (" of #{series}")
@@ -372,14 +363,7 @@ def generate_citation(bibtex_record)
372363
unless address.nil? || (self.booktitle.try(:include?, address))
373364
self.citation += address.nil? ? '' : (", #{address}")
374365
end
375-
=begin
376-
unless self.booktitle.try(:include?, year)
377-
unless year.nil?
378-
self.citation += year.nil? ? '' : (' '+year)
379-
end
380-
end
381-
=end
382-
elsif publication_type.is_inproceedings? || publication_type.is_incollection? || publication_type.is_book?
366+
when publication_type.conferencepaper?, publication_type.collection?, publication_type.book?
383367
# InProceedings / InCollection
384368
self.citation += self.booktitle.nil? ? '' : ("In #{self.booktitle}")
385369
self.citation += volume.blank? ? '' : (", vol. #{volume}")
@@ -390,39 +374,25 @@ def generate_citation(bibtex_record)
390374
unless address.nil? || (self.booktitle.try(:include?, address))
391375
self.citation += address.nil? ? '' : (", #{address}")
392376
end
393-
=begin
394-
unless self.booktitle.try(:include?, year)
395-
unless year.nil?
396-
self.citation += year.nil? ? '' : (', '+year)
397-
end
398-
end
399-
=end
400-
elsif publication_type.is_phd_thesis? || publication_type.is_masters_thesis? || publication_type.is_bachelor_thesis?
377+
when publication_type.dissertation?
401378
#PhD/Master Thesis
402379
self.citation += school.nil? ? '' : (" #{school}")
403380
self.errors.add(:base,'A thesis need to have a school') if school.nil?
404381
self.citation += year.nil? ? '' : (", #{year}")
405382
self.citation += tutor.nil? ? '' : (", #{tutor}(Tutor)")
406383
self.citation += tutorhits.nil? ? '' : (", #{tutorhits}(HITS Tutor)")
407384
self.citation += url.nil? ? '' : (", #{url}")
408-
elsif publication_type.is_proceedings?
385+
when publication_type.conferenceproceeding?
409386
# Proceedings are conference proceedings, it has no authors but editors
410387
# Book
411388
self.journal = self.title
412389
self.citation += volume.blank? ? '' : ("vol. #{volume}")
413390
self.citation += series.blank? ? '' : (" of #{series}")
414391
self.citation += self.publisher.blank? ? '' : (", #{self.publisher}")
415-
=begin
416-
unless month.nil? && year.nil?
417-
self.citation += self.citation.blank? ? '' : ','
418-
self.citation += month.nil? ? '' : (' '+ month.capitalize)
419-
self.citation += year.nil? ? '' : (' '+year)
420-
end
421-
=end
422-
elsif publication_type.is_tech_report?
392+
when publication_type.report?
423393
self.citation += institution.blank? ? ' ': institution
424394
self.citation += type.blank? ? ' ' : (", #{type}")
425-
elsif publication_type.is_unpublished?
395+
when publication_type.preprint?
426396
self.citation += note.blank? ? ' ': note
427397
end
428398

@@ -583,7 +553,7 @@ def pubmed_entry
583553
if pubmed_id
584554
Rails.cache.fetch("bio-reference-#{pubmed_id}") do
585555
entry = Bio::PubMed.efetch(pubmed_id).first
586-
raise "PubMed entry was nil" if entry.nil?
556+
raise 'PubMed entry was nil' if entry.nil?
587557
entry
588558
end
589559
end
@@ -620,25 +590,25 @@ def check_bibtex_file (bibtex_record)
620590

621591

622592
if self.title.blank?
623-
errors.add(:base, "Please check your bibtex files, each publication should contain a title or a chapter name.")
593+
errors.add(:base, 'Please check your bibtex files, each publication should contain a title or a chapter name.')
624594
return false
625595
end
626596

627-
if (%w[InCollection InProceedings].include? self.publication_type.title) && (bibtex_record[:booktitle].blank?)
628-
errors.add(:base, "An #{self.publication_type.title} needs to have a booktitle.")
597+
if (publication_type.collection? || publication_type.conferencepaper?) && bibtex_record[:booktitle].blank?
598+
errors.add(:base, "A #{self.publication_type.title} needs to have a booktitle.")
629599
return false
630600
end
631601

632-
unless %w[Booklet Manual Misc Proceedings].include? self.publication_type.title
602+
unless publication_type.booklet? || publication_type.text? || publication_type.other? || publication_type.conferenceproceeding?
633603
if bibtex_record[:author].nil? && self.editor.nil?
634604
self.errors.add(:base, "You need at least one author or editor for the #{self.publication_type.title}.")
635605
return false
636606
end
637607
end
638608

639-
if self.publication_type.is_phd_thesis? || self.publication_type.is_masters_thesis? || self.publication_type.is_bachelor_thesis?
609+
if publication_type.dissertation?
640610
if bibtex_record[:school].try(:to_s).nil?
641-
self.errors.add(:base,"A #{self.publication_type.title} needs to have a school.")
611+
self.errors.add(:base,"A #{publication_type.title} needs to have a school.")
642612
return false
643613
end
644614
end

0 commit comments

Comments
 (0)