Module: RDF::ID

Defined in:
lib/lightrdf/id.rb

Class Method Summary collapse

Class Method Details

.bnode?(id) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/lightrdf/id.rb', line 13

def self.bnode? id
  id.to_s[0..0] == '_'
end

.compress(uri, ns = {}) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/lightrdf/id.rb', line 30

def self.compress uri, ns={}
  RDF::ID.ns.merge(ns).map.sort_by{|k,v| -v.to_s.size}.each do |k,v|
    if uri.to_s.index(v) == 0
      return "#{k}:#{uri.to_s[v.size..-1]}"
    end
  end
  uri.to_s
end

.countObject



10
# File 'lib/lightrdf/id.rb', line 10

def self.count;   @count;   end

.count=(c) ⇒ Object



11
# File 'lib/lightrdf/id.rb', line 11

def self.count=c; @count=c; end

.nsObject



9
# File 'lib/lightrdf/id.rb', line 9

def self.ns;      @ns;      end

.parse(id, ns = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/lightrdf/id.rb', line 20

def self.parse id, ns={}
  if id.to_s[0..6]!='http://' and id.to_s[0..7]!='https://' and id.to_s[0..0]!='_' and id.to_s =~ /(\w+):(\w.*)/
    :"#{RDF::ID.ns.merge(ns)[$1.to_sym]}#{$2}"
  elsif id == '*' or !id
    :"_:bnode#{@count+=1}"
  else
    id.to_sym
  end
end

.uri?(id) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/lightrdf/id.rb', line 16

def self.uri? id
  !bnode?(id)
end