Module: BioRdf::RDF

Defined in:
lib/bio/writers/rdf.rb

Class Method Summary collapse

Class Method Details

.escape_string_literal(literal) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/bio/writers/rdf.rb', line 11

def RDF::escape_string_literal(literal)
  s = literal.to_s
  # Put a slash before every double quote if there is no such slash already
  s = s.gsub(/(?<!\\)"/,'\"')
  # Put a slash before a single slash if it is not \["utnr>\]
  if s =~ /[^\\]\\[^\\]/
    s2 = []
    s.each_char.with_index { |c,i| 
      res = c
      if i>0 and c == '\\' and s[i-1] != '\\' and s[i+1] !~ /^[uUtnr\\"]/
        res = '\\' + c
      end
      # p [i,c,s[i+1],res]
      s2 << res
    }
    s = s2.join('')
  end
  s
end

.quoted_stringify_literal(literal) ⇒ Object



35
36
37
# File 'lib/bio/writers/rdf.rb', line 35

def RDF::quoted_stringify_literal(literal)
  '"' + stringify_literal(literal) + '"'
end

.stringify_literal(literal) ⇒ Object



31
32
33
# File 'lib/bio/writers/rdf.rb', line 31

def RDF::stringify_literal(literal)
  RDF::escape_string_literal(literal.to_s)
end

.valid_uri?(uri) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/bio/writers/rdf.rb', line 7

def RDF::valid_uri? uri
  uri =~ /^([!#$&-;=?_a-z~]|%[0-9a-f]{2})+$/i
end