Class: Valkyrie::Persistence::Fedora::Persister::ModelConverter::OrderedMembers
- Inherits:
-
ValueMapper
- Object
- ValueMapper
- Valkyrie::Persistence::Fedora::Persister::ModelConverter::OrderedMembers
- 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
Class Method Summary collapse
-
.handles?(value) ⇒ Boolean
Determines whether or not the Valkyrie attribute value can be ordered.
Instance Method Summary collapse
-
#apply_first_and_last ⇒ RDF::Graph
Append the RDF statements asserting that two RDF resources are the "first" and "last" elements of the linked list.
-
#graph ⇒ RDF::Graph
Generate the RDF Graph from from the ordered value array.
-
#initialize_list ⇒ Object
Populate an OrderedList object (wrapping an RDF graph implementation of a linked list) using the value array.
-
#ordered_list ⇒ OrderedList
Construct an OrderedList object.
-
#result ⇒ GraphProperty
Construct a graph from the value array.
Methods inherited from ValueMapper
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
163 164 165 |
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 163 def self.handles?(value) value.is_a?(Property) && value.key == :member_ids && Array(value.value).present? end |
Instance Method Details
#apply_first_and_last ⇒ RDF::Graph
Append the RDF statements asserting that two RDF resources are the "first" and "last" elements of the linked list
183 184 185 186 187 |
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 183 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 |
#graph ⇒ RDF::Graph
Generate the RDF Graph from from the ordered value array
177 178 179 |
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 177 def graph @graph ||= ordered_list.to_graph end |
#initialize_list ⇒ Object
Populate an OrderedList object (wrapping an RDF graph implementation of a linked list) using the value array
190 191 192 193 194 |
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 190 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_list ⇒ OrderedList
Construct an OrderedList object
198 199 200 |
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 198 def ordered_list @ordered_list ||= OrderedList.new(RDF::Graph.new, nil, nil, value.adapter) end |
#result ⇒ GraphProperty
Construct a graph from the value array
169 170 171 172 173 |
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 169 def result initialize_list apply_first_and_last GraphProperty.new(value.subject, value.key, graph, value.adapter, value.resource) end |