Class: JekyllRPG::CollectionDocument

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

Overview

Represents a document that may be in a Jekyll collection, extracted from either a document itself, or a markdown link.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#collectionObject

Returns the value of attribute collection.



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

def collection
  @collection
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#slugObject

Returns the value of attribute slug.



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

def slug
  @slug
end

#viewableObject

Returns the value of attribute viewable.



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

def viewable
  @viewable
end

Instance Method Details

#document_existsObject

Checks whether document exists in a site



29
30
31
# File 'lib/collection_document.rb', line 29

def document_exists
  !@site.collections[@collection].nil? && !find_document.nil?
end

#extract_doc(doc) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/collection_document.rb', line 10

def extract_doc(doc)
  @name = doc.data['name']
  @collection = doc.collection.label
  @slug = doc.data['slug']
  @viewable = true
  self
end

#extract_markdown(site, link) ⇒ Object

extracts link text, collection and slug



19
20
21
22
23
24
25
26
# File 'lib/collection_document.rb', line 19

def extract_markdown(site, link)
  @site = site
  @collection = link.collection
  @slug = link.slug
  @viewable = viewable
  @name = @viewable ? find_document.data['name'] : link.name
  self
end

#find_documentObject

Find a document based on its collection and slug



34
35
36
# File 'lib/collection_document.rb', line 34

def find_document
  @site.collections[@collection].docs.find { |doc| doc.data['slug'] == @slug }
end

#hashObject



48
49
50
51
52
53
54
55
# File 'lib/collection_document.rb', line 48

def hash
  {
    'name' => @name,
    'collection' => @collection,
    'slug' => @slug,
    'link' => markdown_link
  }
end


44
45
46
# File 'lib/collection_document.rb', line 44

def markdown_link
  "[#{@name}](/#{@collection}/#{@slug})"
end