Class: RDF::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/rdf/ext/uri.rb

Instance Method Summary collapse

Instance Method Details

#as(klass, *args) {|self| ... } ⇒ Klass

Create a projection of this Node as the given Spira::Resource class. Equivalent to klass.for(self, *args)

Examples:

Instantiating a blank node as a Spira Resource

RDF::Node.new.as(Person)

Parameters:

  • klass (Class)
  • args (*Any)

    Any arguments to pass to klass.for

Yields:

  • (self)

    Executes a given block and calls #save!

Yield Parameters:

  • self (self)

    The newly created instance

Returns:

  • (Klass)

    An instance of klass

Raises:

  • (ArgumentError)


32
33
34
35
# File 'lib/rdf/ext/uri.rb', line 32

def as(klass, *args)
  raise ArgumentError, "#{klass} is not a Spira resource" unless klass.is_a?(Class) && klass.ancestors.include?(Spira::Base)
  klass.for(self, *args)
end