Module: Source::Bibtex::SoftValidationExtensions::Instance

Included in:
Source::Bibtex
Defined in:
app/models/source/bibtex/soft_validation_extensions.rb

Instance Method Summary collapse

Instance Method Details

#sv_contains_a_writerObject

neither author nor editor



151
152
153
154
155
156
157
# File 'app/models/source/bibtex/soft_validation_extensions.rb', line 151

def sv_contains_a_writer
  if ['book', 'inbook'].include?(bibtex_type)
    if !has_writer?
      soft_validations.add(:base, 'There is neither author, nor editor associated with this source.')
    end
  end
end

#sv_duplicate_titleObject



199
200
201
202
203
204
205
206
# File 'app/models/source/bibtex/soft_validation_extensions.rb', line 199

def sv_duplicate_title
  if !title.blank?
    q = Source::Bibtex.where(title: title).where.not(id: id).limit(1).load
    if q.any?
      soft_validations.add(:title, "Other sources (#{q.count}: #{q.pluck(:id).join(',')}) with this title exists, it may be duplicate")
    end
  end
end

#sv_electronic_onlyObject



195
196
197
# File 'app/models/source/bibtex/soft_validation_extensions.rb', line 195

def sv_electronic_only
  soft_validations.add(:serial_id, 'This article is from the serial which publishes in electronic only format') if self&.serial&.is_electronic_only
end

#sv_has_authorsObject



159
160
161
162
163
164
165
# File 'app/models/source/bibtex/soft_validation_extensions.rb', line 159

def sv_has_authors
  if sv_match_fields?(:author)
    if !(has_authors?)
      soft_validations.add(:author, 'Valid BibTeX requires an author for this type of source.')
    end
  end
end

#sv_has_booktitleObject



134
135
136
137
138
139
140
# File 'app/models/source/bibtex/soft_validation_extensions.rb', line 134

def sv_has_booktitle
  if sv_match_fields?(:booktitle)
    if booktitle.blank?
      soft_validations.add(:booktitle, 'Valid BibTeX requires a book title to be associated with this source.')
    end
  end
end

#sv_has_chapter_or_pagesObject



128
129
130
131
132
# File 'app/models/source/bibtex/soft_validation_extensions.rb', line 128

def sv_has_chapter_or_pages
  if bibtex_type == 'inbook' && chapter.blank? && pages.blank?
    soft_validations.add(:bibtex_type, 'Valid BibTeX requires either a chapter or pages with sources of type inbook.')
  end
end

#sv_has_institutionObject



112
113
114
115
116
117
118
# File 'app/models/source/bibtex/soft_validation_extensions.rb', line 112

def sv_has_institution
  if bibtex_type == 'techreport'
    if institution.blank?
      soft_validations.add(:institution, 'Valid BibTeX requires an institution with a tech report.')
    end
  end
end

#sv_has_noteObject



106
107
108
109
110
# File 'app/models/source/bibtex/soft_validation_extensions.rb', line 106

def sv_has_note
  if bibtex_type == 'unpublished' && note.blank? && !notes.any?
    soft_validations.add(:note, 'Valid BibTeX requires a note with an unpublished source.')
  end
end

#sv_has_publisherObject



142
143
144
145
146
147
148
# File 'app/models/source/bibtex/soft_validation_extensions.rb', line 142

def sv_has_publisher
  if sv_match_fields?(:publisher)
    if publisher.blank?
      soft_validations.add(:publisher, 'Valid BibTeX requires a publisher to be associated with this source.')
    end
  end
end

#sv_has_schoolObject



120
121
122
123
124
125
126
# File 'app/models/source/bibtex/soft_validation_extensions.rb', line 120

def sv_has_school
  if sv_match_fields?(:school)
    if school.blank?
      soft_validations.add(:school, 'Valid BibTeX requires a school associated with any thesis.')
    end
  end
end

#sv_has_some_type_of_yearObject



208
209
210
211
212
# File 'app/models/source/bibtex/soft_validation_extensions.rb', line 208

def sv_has_some_type_of_year
  if !has_some_year?
    soft_validations.add(:base, 'There is no year nor is there a stated year associated with this source.')
  end
end

#sv_has_titleObject



167
168
169
170
171
172
173
# File 'app/models/source/bibtex/soft_validation_extensions.rb', line 167

def sv_has_title
  if sv_match_fields?(:title)
    if title.blank?
      soft_validations.add(:author, 'Valid BibTeX requires a title for this type of source.')
    end
  end
end

#sv_has_yearObject



175
176
177
178
179
180
181
182
183
# File 'app/models/source/bibtex/soft_validation_extensions.rb', line 175

def sv_has_year
  if sv_match_fields?(:year)
    if year.blank?
      soft_validations.add(:year, 'Valid BibTeX requires a year with this type of source.')
    elsif year < 1700
      soft_validations.add(:year, 'This year is prior to the 1700s.')
    end
  end
end

#sv_is_article_missing_journalObject



185
186
187
188
189
190
191
192
193
# File 'app/models/source/bibtex/soft_validation_extensions.rb', line 185

def sv_is_article_missing_journal
  if bibtex_type == 'article'
    if journal.nil? && serial_id.nil?
      soft_validations.add(:bibtex_type, 'This article is missing a journal name.')
    elsif serial_id.nil?
      soft_validations.add(:serial_id, 'This article is missing a serial.')
    end
  end
end

#sv_match_fields?(field) ⇒ Boolean

Returns:

  • (Boolean)


102
103
104
# File 'app/models/source/bibtex/soft_validation_extensions.rb', line 102

def sv_match_fields?(field)
  Source::Bibtex::BIBTEX_REQUIRED_FIELDS[bibtex_type.to_sym]&.include?(field)
end

#sv_missing_rolesObject



214
215
216
# File 'app/models/source/bibtex/soft_validation_extensions.rb', line 214

def sv_missing_roles
  soft_validations.add(:base, 'Author roles are not selected.') if author_roles.empty?
end