Module: Shared::Uri

Extended by:
ActiveSupport::Concern
Included in:
AnatomicalPart, ControlledVocabularyTerm, Identifier::Global::Uri
Defined in:
app/models/concerns/shared/uri.rb

Instance Method Summary collapse

Instance Method Details

#uri_attributeObject



16
17
18
# File 'app/models/concerns/shared/uri.rb', line 16

def uri_attribute
  read_attribute(self.class.uri_column)
end

#valid_uriObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/models/concerns/shared/uri.rb', line 20

def valid_uri
  return if uri_attribute.nil?

  uris = URI.extract(uri_attribute)

  if uris.count == 0
    errors.add(uri_column, 'Provided URI is unparsable.')
  elsif uris.count > 1 || uris[0].length != uri_attribute.length
    errors.add(uri_column, 'More than a single URI present.')
  else
    begin
      u = URI(uri_attribute)
      scheme = u.scheme.upcase
      unless URI.scheme_list.keys.include?(scheme)
        errors.add(uri_column, "#{scheme} is not in the URI schemes list.")
      end
    rescue
      errors.add(uri_column, "Badly formed URI #{uri_attribute} detected.")
    end
  end
end