Class: Valkyrie::Persistence::Fedora::Persister::OrmConverter::GraphToAttributes::NestedValue

Inherits:
ValueMapper
  • Object
show all
Defined in:
lib/valkyrie/persistence/fedora/persister/orm_converter.rb

Overview

Class for mapping RDF child graphs within parent graphs

Defined Under Namespace

Classes: GraphContainer

Instance Attribute Summary

Attributes inherited from ValueMapper

#calling_mapper, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ValueMapper

for, #initialize, register

Constructor Details

This class inherits a constructor from Valkyrie::ValueMapper

Class Method Details

.handles?(value) ⇒ Boolean

Determines whether or not a Property lies within a parent graph

Parameters:

Returns:

  • (Boolean)


226
227
228
229
230
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 226

def self.handles?(value)
  value.statement.object.is_a?(RDF::URI) && value.statement.object.to_s.include?("#") &&
    (value.statement.object.to_s.start_with?("#") ||
     value.statement.object.to_s.start_with?(value.adapter.connection_prefix))
end

Instance Method Details

#containerGraphContainer

Construct a new GraphContainer object for the parent graph of the child graph in this Property

Returns:



246
247
248
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 246

def container
  GraphContainer.new(graph, value.statement.object)
end

#graphRDF::Graph

Construct the RDF graph used for the parent graph

Returns:

  • (RDF::Graph)


270
271
272
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 270

def graph
  @graph ||= RDF::Graph.new
end

#new_subject(statement) ⇒ RDF::URI

Retrieve a new RDF subject for a given statement

If the subject of the statement and that of the Property statement are the same, generate an empty URI

Parameters:

  • statement (RDF::Statement)

Returns:



260
261
262
263
264
265
266
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 260

def new_subject(statement)
  if statement.subject == value.statement.object
    RDF::URI("")
  else
    statement.subject
  end
end

#resourceValkyrie::Resource

Recursively convert the parent graph into a Valkyrie Resource

Returns:



252
253
254
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 252

def resource
  OrmConverter.new(object: container, adapter: value.adapter).convert
end

#resultApplicator

Construct an Applicator object from the parent graph for the child graph in this Property

Returns:



234
235
236
237
238
239
240
241
242
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 234

def result
  value.scope.each do |statement|
    next unless statement.subject.to_s.include?("#")
    subject = new_subject(statement)
    graph << RDF::Statement.new(subject, statement.predicate, statement.object)
  end
  value.statement.object = resource
  Applicator.new(Property.new(statement: value.statement, scope: value.scope, adapter: value.adapter))
end