Class: JekyllRPG::Graph

Inherits:
Object
  • Object
show all
Defined in:
lib/graph.rb

Overview

Graph of relationships between CollectionDocuments

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGraph

Returns a new instance of Graph.



8
9
10
# File 'lib/graph.rb', line 8

def initialize
  @edges = []
end

Instance Attribute Details

#edgesObject

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

#hashObject



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

#unviewableObject

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