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
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_last ⇒ RDF::Graph
Append the RDF statements asserting that two RDF resources are the “first” and “last” elements of the linked list
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 |
#graph ⇒ RDF::Graph
Generate the RDF Graph from from the ordered value array
171 172 173 |
# File 'lib/valkyrie/persistence/fedora/persister/model_converter.rb', line 171 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
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_list ⇒ OrderedList
Construct an OrderedList object
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 |
#result ⇒ GraphProperty
Construct a graph from the value array
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 |