Class: Valkyrie::Persistence::Fedora::Persister::ModelConverter::OrderedMembers

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

Overview

Class mapping Fedora property values which must be ordered This assumes that the value being mapped is actually an Array (or Enumerable)

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 the Valkyrie attribute value can be ordered

Parameters:

  • value (Object)

Returns:

  • (Boolean)


157
158
159
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 157

def self.handles?(value)
  value.is_a?(Property) && value.key == :member_ids && Array(value.value).present?
end

Instance Method Details

#apply_first_and_lastRDF::Graph

Append the RDF statements asserting that two RDF resources are the “first” and “last” elements of the linked list

Returns:

  • (RDF::Graph)


177
178
179
180
181
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 177

def apply_first_and_last
  return if ordered_list.to_a.empty?
  graph << RDF::Statement.new(value.subject, ::RDF::Vocab::IANA.first, ordered_list.head.next.rdf_subject)
  graph << RDF::Statement.new(value.subject, ::RDF::Vocab::IANA.last, ordered_list.tail.prev.rdf_subject)
end

#graphRDF::Graph

Generate the RDF Graph from from the ordered value array

Returns:

  • (RDF::Graph)


171
172
173
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 171

def graph
  @graph ||= ordered_list.to_graph
end

#initialize_listObject

Populate an OrderedList object (wrapping an RDF graph implementation of a linked list) using the value array



184
185
186
187
188
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 184

def initialize_list
  Array(value.value).each_with_index do |val, index|
    ordered_list.insert_proxy_for_at(index, calling_mapper.for(Property.new(value.subject, :member_id, val, value.adapter, value.resource)).result.value)
  end
end

#ordered_listOrderedList

Construct an OrderedList object

Returns:



192
193
194
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 192

def ordered_list
  @ordered_list ||= OrderedList.new(RDF::Graph.new, nil, nil, value.adapter)
end

#resultGraphProperty

Construct a graph from the value array

Returns:



163
164
165
166
167
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 163

def result
  initialize_list
  apply_first_and_last
  GraphProperty.new(value.subject, value.key, graph, value.adapter, value.resource)
end