Module: Label::SKOSXL::Validations

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
app/models/label/skosxl/validations.rb

Instance Method Summary collapse

Instance Method Details

#origin_has_to_be_escapedObject



17
18
19
20
21
# File 'app/models/label/skosxl/validations.rb', line 17

def origin_has_to_be_escaped
  unless Origin.new(origin).valid?
    errors.add :base, I18n.t('txt.models.label.origin_invalid')
  end
end

#pref_label_languageObject



23
24
25
26
27
28
29
30
# File 'app/models/label/skosxl/validations.rb', line 23

def pref_label_language
  invalid_pref_label_language = ::Iqvoc::Concept.pref_labeling_languages.exclude?(language)
  has_pref_labeled_concepts = concepts_for_labeling_class(::Iqvoc::Concept.pref_labeling_class).any?

  if invalid_pref_label_language && has_pref_labeled_concepts
    errors.add :base, I18n.t('txt.models.label.pref_label_language')
  end
end

#referenced_published_concepts_have_main_language_pref_labelObject



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/models/label/skosxl/validations.rb', line 32

def referenced_published_concepts_have_main_language_pref_label
  published_label = self.published_version

  # check published concepts which use the current label as a pref label
  concepts.published.each do |concept|
    # pref labels without the current published one
    pref_labels = concept.pref_labels.reject { |l| l == published_label }

    unless pref_labels.map(&:language).map(&:to_s).include?(::Iqvoc::Concept.pref_labeling_languages.first.to_s)
      errors.add :base, I18n.t('txt.models.label.referenced_concepts_invalid')
    end
  end
end