Module: BioVcf::RDF

Defined in:
lib/bio-vcf/vcfrdf.rb

Overview

RDF support module. Original is part of bioruby-rdf by Pjotr Prins

Class Method Summary collapse

Class Method Details

.escape_string_literal(literal) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/bio-vcf/vcfrdf.rb', line 51

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



75
76
77
# File 'lib/bio-vcf/vcfrdf.rb', line 75

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

.stringify_literal(literal) ⇒ Object



71
72
73
# File 'lib/bio-vcf/vcfrdf.rb', line 71

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

.valid_uri?(uri) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/bio-vcf/vcfrdf.rb', line 47

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