Class: JekyllRPG::CollectionDocument
- Inherits:
-
Object
- Object
- JekyllRPG::CollectionDocument
- 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
-
#collection ⇒ Object
Returns the value of attribute collection.
-
#name ⇒ Object
Returns the value of attribute name.
-
#slug ⇒ Object
Returns the value of attribute slug.
-
#viewable ⇒ Object
Returns the value of attribute viewable.
Instance Method Summary collapse
-
#document_exists ⇒ Object
Checks whether document exists in a site.
- #extract_doc(doc) ⇒ Object
-
#extract_markdown(site, link) ⇒ Object
extracts link text, collection and slug.
-
#find_document ⇒ Object
Find a document based on its collection and slug.
- #hash ⇒ Object
- #markdown_link ⇒ Object
Instance Attribute Details
#collection ⇒ Object
Returns the value of attribute collection.
8 9 10 |
# File 'lib/collection_document.rb', line 8 def collection @collection end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/collection_document.rb', line 8 def name @name end |
#slug ⇒ Object
Returns the value of attribute slug.
8 9 10 |
# File 'lib/collection_document.rb', line 8 def slug @slug end |
#viewable ⇒ Object
Returns the value of attribute viewable.
8 9 10 |
# File 'lib/collection_document.rb', line 8 def viewable @viewable end |
Instance Method Details
#document_exists ⇒ Object
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_document ⇒ Object
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 |
#hash ⇒ Object
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 |
#markdown_link ⇒ Object
44 45 46 |
# File 'lib/collection_document.rb', line 44 def markdown_link "[#{@name}](/#{@collection}/#{@slug})" end |