Class: Samvera::NestingIndexer::Documents::IndexDocument
- Inherits:
-
Object
- Object
- Samvera::NestingIndexer::Documents::IndexDocument
- Defined in:
- lib/samvera/nesting_indexer/documents.rb
Overview
A rudimentary representation of what is needed to reindex Solr documents
Instance Attribute Summary collapse
-
#ancestors ⇒ Object
readonly
All of the :pathnames of each of the documents ancestors.
-
#id ⇒ Object
readonly
String The Fedora object’s PID.
-
#parent_ids ⇒ Object
readonly
All of the direct parents of the Fedora document associated with the given PID.
-
#pathnames ⇒ Object
readonly
All nodes in the graph are addressable by one or more pathnames.
Instance Method Summary collapse
-
#deepest_nested_depth ⇒ Object
The largest nesting depth of this document.
-
#initialize(keywords = {}) ⇒ IndexDocument
constructor
A new instance of IndexDocument.
- #sorted_ancestors ⇒ Object
- #sorted_parent_ids ⇒ Object
- #sorted_pathnames ⇒ Object
-
#to_hash ⇒ Hash<Symbol,>
The Ruby hash representation of this index document.
Constructor Details
#initialize(keywords = {}) ⇒ IndexDocument
Returns a new instance of IndexDocument.
38 39 40 41 42 43 |
# File 'lib/samvera/nesting_indexer/documents.rb', line 38 def initialize(keywords = {}) @id = keywords.fetch(:id).to_s @parent_ids = Array(keywords.fetch(:parent_ids)) @pathnames = Array(keywords.fetch(:pathnames)) @ancestors = Array(keywords.fetch(:ancestors)) end |
Instance Attribute Details
#ancestors ⇒ Object (readonly)
All of the :pathnames of each of the documents ancestors. If I have A, with parent B, and B has parents C and D then we have the following ancestors:
[D], [C], [D/B], [C/B]
89 90 91 |
# File 'lib/samvera/nesting_indexer/documents.rb', line 89 def ancestors @ancestors end |
#id ⇒ Object (readonly)
Returns String The Fedora object’s PID.
60 61 62 |
# File 'lib/samvera/nesting_indexer/documents.rb', line 60 def id @id end |
#parent_ids ⇒ Object (readonly)
All of the direct parents of the Fedora document associated with the given PID.
This does not include grandparents, great-grandparents, etc.
68 69 70 |
# File 'lib/samvera/nesting_indexer/documents.rb', line 68 def parent_ids @parent_ids end |
#pathnames ⇒ Object (readonly)
All nodes in the graph are addressable by one or more pathnames.
If I have A, with parent B, and B has parents C and D, we have the following pathnames:
[D/B/A, C/B/A]
In the graph representation, we can get to A by going from D to B to A, or by going from C to B to A.
80 81 82 |
# File 'lib/samvera/nesting_indexer/documents.rb', line 80 def pathnames @pathnames end |
Instance Method Details
#deepest_nested_depth ⇒ Object
The largest nesting depth of this document. If I have A ={ B ={ C and D ={ C, then deepest_nested_depth is 3.
98 99 100 |
# File 'lib/samvera/nesting_indexer/documents.rb', line 98 def deepest_nested_depth pathnames.map(&:length).max end |
#sorted_ancestors ⇒ Object
110 111 112 |
# File 'lib/samvera/nesting_indexer/documents.rb', line 110 def sorted_ancestors ancestors.sort end |
#sorted_parent_ids ⇒ Object
102 103 104 |
# File 'lib/samvera/nesting_indexer/documents.rb', line 102 def sorted_parent_ids parent_ids.sort end |
#sorted_pathnames ⇒ Object
106 107 108 |
# File 'lib/samvera/nesting_indexer/documents.rb', line 106 def sorted_pathnames pathnames.sort end |
#to_hash ⇒ Hash<Symbol,>
Returns the Ruby hash representation of this index document.
48 49 50 51 52 53 54 55 56 |
# File 'lib/samvera/nesting_indexer/documents.rb', line 48 def to_hash { id: id, parent_ids: parent_ids, pathnames: pathnames, ancestors: ancestors, deepest_nested_depth: deepest_nested_depth } end |