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



145
146
147
148
149
150
151
# File 'app/models/source/bibtex/soft_validation_extensions.rb', line 145

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



189
190
191
192
193
194
195
196
# File 'app/models/source/bibtex/soft_validation_extensions.rb', line 189

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_has_authorsObject



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

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



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

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



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

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



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

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



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

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



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

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



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

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



198
199
200
201
202
# File 'app/models/source/bibtex/soft_validation_extensions.rb', line 198

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



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

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



169
170
171
172
173
174
175
176
177
# File 'app/models/source/bibtex/soft_validation_extensions.rb', line 169

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



179
180
181
182
183
184
185
186
187
# File 'app/models/source/bibtex/soft_validation_extensions.rb', line 179

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)


96
97
98
# File 'app/models/source/bibtex/soft_validation_extensions.rb', line 96

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

#sv_missing_rolesObject



204
205
206
# File 'app/models/source/bibtex/soft_validation_extensions.rb', line 204

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