Class: RDFObject::BlankNode

Inherits:
OpenStruct
  • Object
show all
Includes:
Node
Defined in:
lib/rdf_objects/rdf_resource.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Node

#==, #[], #assert, #assertion_exists?, #assertions, #empty_graph?, #object_to_json_hash, #prefix_for, #rdf_description_block, #register_vocabulary, #relate, #to_json, #to_json_hash, #to_ntriples, #to_xml

Constructor Details

#initialize(node_id = nil) ⇒ BlankNode

Returns a new instance of BlankNode.



276
277
278
# File 'lib/rdf_objects/rdf_resource.rb', line 276

def initialize(node_id = nil)        
  super(:node_id=>sanitize_bnode_id(node_id||"o#{object_id}"))
end

Class Method Details

.is_bnode_id?(str) ⇒ Boolean

Returns:

  • (Boolean)


298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/rdf_objects/rdf_resource.rb', line 298

def self.is_bnode_id?(str)
  return true if str =~ /^_\:/
  if str.could_be_a_safe_curie?
    str = Curie.parse str
  end
  begin
    uri = Addressable::URI.parse(str).normalize
    return true if uri.scheme.nil? or !uri.scheme =~ /[A-z]/
  rescue URI::InvalidURIError
    return true
  end
  return false  
end

Instance Method Details

#describeObject



280
# File 'lib/rdf_objects/rdf_resource.rb', line 280

def describe; end

#ntriples_formatObject



294
295
296
# File 'lib/rdf_objects/rdf_resource.rb', line 294

def ntriples_format
  uri
end

#sanitize_bnode_id(str) ⇒ Object



312
313
314
# File 'lib/rdf_objects/rdf_resource.rb', line 312

def sanitize_bnode_id(str)
  str.sub(/^_\:/,"")
end

#uriObject



282
283
284
# File 'lib/rdf_objects/rdf_resource.rb', line 282

def uri
  "_:#{self.node_id}"
end

#xml_object_attributeObject



290
291
292
# File 'lib/rdf_objects/rdf_resource.rb', line 290

def xml_object_attribute
  xml_subject_attribute
end

#xml_subject_attributeObject



286
287
288
# File 'lib/rdf_objects/rdf_resource.rb', line 286

def xml_subject_attribute
  "rdf:nodeID=\"#{self.node_id}\""
end