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)


233
234
235
236
237
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 233

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:



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

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

#graphRDF::Graph

Construct the RDF graph used for the parent graph

Returns:

  • (RDF::Graph)


277
278
279
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 277

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:



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

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:



259
260
261
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 259

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:



241
242
243
244
245
246
247
248
249
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 241

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