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)


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

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:



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

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

#graphRDF::Graph

Construct the RDF graph used for the parent graph

Returns:

  • (RDF::Graph)


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

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:



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

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:



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

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:



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

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