Sha256: 154e4944f69d152ad85d977247b672d0ab92d86c280625d384e5607bf84ffa82

Contents?: true

Size: 657 Bytes

Versions: 5

Compression:

Stored size: 657 Bytes

Contents

module TaliaUtil
  
  # Some helper methods to deal with URI and IRI strings
  module UriHelper
    
    # Removes all characters that are illegal in IRIs, so that the
    # URIs can be imported
    def irify(uri)
      N::URI.new(uri.to_s.gsub( /[<>"{}|\\^`\s]/, '+')).to_s
    end
    
    # Sanitize an URI to be passed into SPARQL queries
    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
    
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
talia_core-0.7.0 lib/talia_util/uri_helper.rb
talia_core-0.5.4 lib/talia_util/uri_helper.rb
talia_core-0.5.3 lib/talia_util/uri_helper.rb
talia_core-0.5.2 lib/talia_util/uri_helper.rb
talia_core-0.5.1 lib/talia_util/uri_helper.rb