Module: TaliaUtil::UriHelper

Included in:
Swicky::Notebook, Swicky::Notebook, TaliaCore::ActiveSourceParts::Xml::GenericReader
Defined in:
lib/talia_util/uri_helper.rb

Overview

Some helper methods to deal with URI and IRI strings

Instance Method Summary collapse

Instance Method Details

#irify(uri) ⇒ Object

Removes all characters that are illegal in IRIs, so that the URIs can be imported



8
9
10
# File 'lib/talia_util/uri_helper.rb', line 8

def irify(uri)
  N::URI.new(uri.to_s.gsub( /[<>"{}|\\^`\s]/, '+')).to_s
end

#sanitize_sparql(uri_or_string) ⇒ Object

Sanitize an URI to be passed into SPARQL queries



13
14
15
16
17
# File 'lib/talia_util/uri_helper.rb', line 13

def sanitize_sparql(uri_or_string)
  uri_or_string = uri_or_string.to_s.gsub( /[<>"{}|\\^`\s]/, '') # Remove forbidden chars that we know of
  URI.escape(uri_or_string) # Escape everything else
  uri_or_string.gsub('%23', '#') # Revert the hash character, we need that intact
end