Class: JekyllRPG::Graph
- Inherits:
-
Object
- Object
- JekyllRPG::Graph
- Defined in:
- lib/graph.rb
Overview
Graph of relationships between CollectionDocuments
Instance Attribute Summary collapse
-
#edges ⇒ Object
Returns the value of attribute edges.
Instance Method Summary collapse
-
#document_references(doc) ⇒ Object
Get the information for every page the current doc is referenced in And push links to an array that represents the collections of those pages.
- #hash ⇒ Object
-
#initialize ⇒ Graph
constructor
A new instance of Graph.
-
#referenced_in(doc) ⇒ Object
Based on the graph, returns edges that a specific document is the referent of.
-
#unviewable ⇒ Object
Based on the graph, returns documents that are referenced, but do not exist yet.
Constructor Details
#initialize ⇒ Graph
Returns a new instance of Graph.
8 9 10 |
# File 'lib/graph.rb', line 8 def initialize @edges = [] end |
Instance Attribute Details
#edges ⇒ Object
Returns the value of attribute edges.
6 7 8 |
# File 'lib/graph.rb', line 6 def edges @edges end |
Instance Method Details
#document_references(doc) ⇒ Object
Get the information for every page the current doc is referenced in And push links to an array that represents the collections of those pages
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/graph.rb', line 14 def document_references(doc) document_hash = {} referenced_in(doc).each do |reference| document_hash[reference.collection] = [] unless document_hash.key?(reference.collection) document_hash[reference.collection].push(reference.markdown_link) end document_hash.each do |k, v| document_hash[k] = v.uniq end document_hash end |
#hash ⇒ Object
44 45 46 |
# File 'lib/graph.rb', line 44 def hash @edges.map(&:hash) end |
#referenced_in(doc) ⇒ Object
Based on the graph, returns edges that a specific document is the referent of
29 30 31 32 33 34 35 |
# File 'lib/graph.rb', line 29 def referenced_in(doc) collection = doc.collection.label slug = doc.data['slug'] @edges.select do |edge| edge.reference.collection == collection && edge.reference.slug == slug end.map(&:referent) end |
#unviewable ⇒ Object
Based on the graph, returns documents that are referenced, but do not exist yet
38 39 40 41 42 |
# File 'lib/graph.rb', line 38 def unviewable @edges.reject do |edge| edge.reference.viewable end end |