Skip to content

Commit e363eda

Browse files
committed
update code according to the PR review.
1 parent 38eb875 commit e363eda

File tree

8 files changed

+180
-39
lines changed

8 files changed

+180
-39
lines changed

app/models/publication.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -345,15 +345,15 @@ def generate_citation(bibtex_record)
345345
publication_type = PublicationType.find(self.publication_type_id)
346346

347347
case publication_type.key
348-
when 'journalarticle'
348+
when publication_type.journalarticle?
349349
self.citation += self.journal.nil? ? '':self.journal
350350
self.citation += volume.blank? ? '': " #{volume}"
351351
self.citation += number.nil? ? '' : "(#{number})"
352352
self.citation += pages.blank? ? '' : (":#{pages}")
353-
when 'booklet'
353+
when publication_type.booklet?
354354
self.citation += howpublished.blank? ? '': "#{howpublished}"
355355
self.citation += address.nil? ? '' : (", #{address}")
356-
when 'bookchapter'
356+
when publication_type.bookchapter?
357357
self.citation += self.booktitle.nil? ? '' : ("In #{self.booktitle}")
358358
self.citation += volume.blank? ? '' : (", volume #{volume}")
359359
self.citation += series.blank? ? '' : (" of #{series}")
@@ -363,7 +363,7 @@ def generate_citation(bibtex_record)
363363
unless address.nil? || (self.booktitle.try(:include?, address))
364364
self.citation += address.nil? ? '' : (", #{address}")
365365
end
366-
when 'conferencepaper', 'collection', 'book'
366+
when publication_type.conferencepaper?, publication_type.collection?, publication_type.book?
367367
# InProceedings / InCollection
368368
self.citation += self.booktitle.nil? ? '' : ("In #{self.booktitle}")
369369
self.citation += volume.blank? ? '' : (", vol. #{volume}")
@@ -374,25 +374,25 @@ def generate_citation(bibtex_record)
374374
unless address.nil? || (self.booktitle.try(:include?, address))
375375
self.citation += address.nil? ? '' : (", #{address}")
376376
end
377-
when 'bachelorsthesis', 'mastersthesis', 'phdthesis'
377+
when publication_type.dissertation?
378378
#PhD/Master Thesis
379379
self.citation += school.nil? ? '' : (" #{school}")
380380
self.errors.add(:base,'A thesis need to have a school') if school.nil?
381381
self.citation += year.nil? ? '' : (", #{year}")
382382
self.citation += tutor.nil? ? '' : (", #{tutor}(Tutor)")
383383
self.citation += tutorhits.nil? ? '' : (", #{tutorhits}(HITS Tutor)")
384384
self.citation += url.nil? ? '' : (", #{url}")
385-
when 'conferenceproceeding'
385+
when publication_type.conferenceproceeding?
386386
# Proceedings are conference proceedings, it has no authors but editors
387387
# Book
388388
self.journal = self.title
389389
self.citation += volume.blank? ? '' : ("vol. #{volume}")
390390
self.citation += series.blank? ? '' : (" of #{series}")
391391
self.citation += self.publisher.blank? ? '' : (", #{self.publisher}")
392-
when 'report'
392+
when publication_type.report?
393393
self.citation += institution.blank? ? ' ': institution
394394
self.citation += type.blank? ? ' ' : (", #{type}")
395-
when 'preprint'
395+
when publication_type.preprint?
396396
self.citation += note.blank? ? ' ': note
397397
end
398398

@@ -594,21 +594,21 @@ def check_bibtex_file (bibtex_record)
594594
return false
595595
end
596596

597-
if (['Collection', 'Conference Paper'].include? self.publication_type.title) && (bibtex_record[:booktitle].blank?)
597+
if (publication_type.collection? || publication_type.conferencepaper?) && bibtex_record[:booktitle].blank?
598598
errors.add(:base, "A #{self.publication_type.title} needs to have a booktitle.")
599599
return false
600600
end
601601

602-
unless ['Booklet', 'Text', 'Other', 'Conference Proceeding'].include? self.publication_type.title
602+
unless publication_type.booklet? || publication_type.text? || publication_type.other? || publication_type.conferenceproceeding?
603603
if bibtex_record[:author].nil? && self.editor.nil?
604604
self.errors.add(:base, "You need at least one author or editor for the #{self.publication_type.title}.")
605605
return false
606606
end
607607
end
608608

609-
if ['bachelorsthesis', 'mastersthesis', 'phdthesis', 'diplomthesis'].include?(publication_type.key)
609+
if publication_type.dissertation?
610610
if bibtex_record[:school].try(:to_s).nil?
611-
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.")
612612
return false
613613
end
614614
end

app/models/publication_type.rb

Lines changed: 145 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,155 @@ class PublicationType < ActiveRecord::Base
2121
}.freeze
2222

2323

24-
# Load expected publication types from YAML
25-
def self.type_registry
26-
@type_registry ||= begin
27-
path = Rails.root.join('config/default_data/publication_types.yml')
28-
YAML.load_file(path).values.index_by { |h| h['title'] }
29-
end
24+
def journalarticle?
25+
key == 'journalarticle'
3026
end
3127

32-
def self.for_type(type)
33-
yaml_entry = type_registry[type]
34-
return nil unless yaml_entry
35-
find_by(key: yaml_entry['key'])
28+
def book?
29+
key == 'book'
3630
end
3731

32+
def booklet?
33+
key == 'booklet'
34+
end
35+
36+
def bookchapter?
37+
key == 'bookchapter'
38+
end
39+
40+
def collection?
41+
key == 'collection'
42+
end
43+
44+
def conferencepaper?
45+
key == 'conferencepaper'
46+
end
47+
48+
def conferenceproceeding?
49+
key == 'conferenceproceeding'
50+
end
51+
52+
def text?
53+
key == 'text'
54+
end
55+
56+
def bachelorsthesis?
57+
key == 'bachelorsthesis'
58+
end
59+
60+
def mastersthesis?
61+
key == 'mastersthesis'
62+
end
63+
64+
def diplomathesis?
65+
key == 'diplomathesis'
66+
end
67+
68+
def phdthesis?
69+
key == 'phdthesis'
70+
end
71+
72+
def dissertation?
73+
%w[bachelorsthesis mastersthesis diplomathesis phdthesis].include?(key)
74+
end
75+
76+
def other?
77+
key == 'other'
78+
end
79+
80+
def preprint?
81+
key == 'preprint'
82+
end
83+
84+
def report?
85+
key == 'report'
86+
end
87+
88+
def audiovisual?
89+
key == 'audiovisual'
90+
end
91+
92+
def award?
93+
key == 'award'
94+
end
95+
96+
def computationalnotebook?
97+
key == 'computationalnotebook'
98+
end
99+
100+
def datapaper?
101+
key == 'datapaper'
102+
end
103+
104+
def dataset?
105+
key == 'dataset'
106+
end
107+
108+
def event?
109+
key == 'event'
110+
end
111+
112+
def image?
113+
key == 'image'
114+
end
115+
116+
def instrument?
117+
key == 'instrument'
118+
end
119+
120+
def interactiveresource?
121+
key == 'interactiveresource'
122+
end
123+
124+
def model?
125+
key == 'model'
126+
end
127+
128+
def outputmanagementplan?
129+
key == 'outputmanagementplan'
130+
end
131+
132+
def peerreview?
133+
key == 'peerreview'
134+
end
135+
136+
def physicalobject?
137+
key == 'physicalobject'
138+
end
139+
140+
def project?
141+
key == 'project'
142+
end
143+
144+
def service?
145+
key == 'service'
146+
end
147+
148+
def software?
149+
key == 'software'
150+
end
151+
152+
def sound?
153+
key == 'sound'
154+
end
155+
156+
def standard?
157+
key == 'standard'
158+
end
159+
160+
def studyregistration?
161+
key == 'studyregistration'
162+
end
163+
164+
def workflow?
165+
key == 'workflow'
166+
end
167+
168+
def projectdeliverable?
169+
key == 'projectdeliverable'
170+
end
171+
172+
38173
# Extract publication type from BibTeX record
39174
def self.get_publication_type_id(bibtex_record)
40175
# Extract the BibTeX entry type, e.g. article, inbook, misc...

app/views/publications/new.html.erb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@
2929
<div class="col-sm-3">
3030
<span id="publication_type_info" style="display:none;"></span>
3131
<span id="publication_type_selection">
32-
<%= collection_select :publication, :publication_type_id, PublicationType.order(:title), :id, :title,
33-
{:selected => PublicationType.JournalArticle.id},
34-
{:class => 'form-control'} -%>
35-
</span>
32+
<%= collection_select :publication, :publication_type_id,
33+
PublicationType.order(:title),
34+
:id, :title,
35+
{ include_blank: "Please select a type ..." },
36+
{ class: "form-control" } %>
37+
</span>
3638
</div>
3739
</div>
3840
</div>
@@ -78,9 +80,11 @@
7880
<div class="col-sm-2">
7981
<span id="publication_type_info" style="display:none;"></span>
8082
<span id="publication_type_selection">
81-
<%= collection_select :publication, :publication_type_id, PublicationType.order(:title), :id, :title,
82-
{:selected => PublicationType.JournalArticle.id},
83-
{:class => 'form-control'} -%>
83+
<%= collection_select :publication, :publication_type_id,
84+
PublicationType.order(:title),
85+
:id, :title,
86+
{ include_blank: "Please select a type ..." },
87+
{ class: "form-control" } %>
8488
</span>
8589
</div>
8690
</div>

config/default_data/publication_types.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ MastersThesis:
4545
key: mastersthesis
4646

4747
DiplomaThesis:
48-
title: Diplom Thesis
49-
key: diplomthesis
48+
title: Diploma Thesis
49+
key: diplomathesis
5050

5151
PhdThesis:
52-
title: Doctoral Thesis
52+
title: PhD Thesis
5353
key: phdthesis
5454

5555
Other:

db/seeds/005_publication_types.seeds.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
'Manual' => 'Text',
2020
'Misc' => 'Other',
2121
'Tech report' => 'Report',
22-
'Unpublished' => 'Preprint'
22+
'Unpublished' => 'Preprint',
23+
'Doctoral Thesis' => 'PhD Thesis',
24+
'Diplom Thesis' => 'Diploma Thesis'
2325
}.freeze
2426

2527
# -------------------------------------------------------------------

test/factories/publications.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
factory(:phdthesis, class: PublicationType) do
11-
title { 'Doctoral Thesis' }
11+
title { 'PhD Thesis' }
1212
key { 'phdthesis' }
1313
end
1414

test/fixtures/publication_types.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ MastersThesis:
4545
key: mastersthesis
4646

4747
DiplomaThesis:
48-
title: Diplom Thesis
49-
key: diplomthesis
48+
title: Diploma Thesis
49+
key: diplomathesis
5050

5151
PhdThesis:
52-
title: Doctoral Thesis
52+
title: PhD Thesis
5353
key: phdthesis
5454

5555
Other:

test/functional/publications_controller_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ def test_title
303303
assert_includes flash[:error], 'A Conference Paper needs to have a booktitle.'
304304
assert_includes flash[:error], 'Please check your bibtex files, each publication should contain a title or a chapter name.'
305305
assert_includes flash[:error], 'A Collection needs to have a booktitle.'
306-
assert_includes flash[:error], 'A Doctoral Thesis needs to have a school.'
306+
assert_includes flash[:error], 'A PhD Thesis needs to have a school.'
307307
assert_includes flash[:error], "A Master's Thesis needs to have a school."
308308
assert_includes flash[:error], 'You need at least one author or editor for the Journal Article.'
309309
end
@@ -315,7 +315,7 @@ def test_title
315315
{ title: 'The Example Book', type_title: 'Book' },
316316
{ title: 'A Chapter Inside a Book', type_title: 'Book Chapter' },
317317
{ title: 'A Conference Paper Example', type_title: 'Conference Paper' },
318-
{ title: 'An Example PhD Thesis', type_title: 'Doctoral Thesis' },
318+
{ title: 'An Example PhD Thesis', type_title: 'PhD Thesis' },
319319
{ title: 'A Technical Report Example', type_title: 'Report' },
320320
{ title: 'Miscellaneous Example', type_title: 'Other' }
321321
]

0 commit comments

Comments
 (0)