Utopia::ProjectSourceUtopiaProjectGuides

class Guides

A collection of guides with navigation and lookup capabilities.

Definitions

def initialize(base, links)

Initialize the guides collection.

Signature

parameter base Base

The base instance for the project.

parameter links Object

The links index for finding guides.

Implementation

def initialize(base, links)
	@base = base
	@links = links
end

def each(&block)

Iterate over all guides.

Signature

yields {|guide| ...}

If a block is given.

parameter guide Guide
returns Enumerator(Guide)

If no block is given.

Implementation

def each(&block)
	return to_enum(:each) unless block_given?
	
	@links.index("/guides").each do |link|
		guide_path = File.join(@base.root, link.path)
		
		next unless File.directory?(guide_path)
		
		yield Guide.new(@base, guide_path, link.info)
	end
end

def to_a

Get all guides as a sorted array.

Signature

returns Array(Guide)

Implementation

def to_a
	@array ||= super.sort
end

def [](name)

Find a guide by name.

Signature

parameter name String

The guide name.

returns Guide | Nil

Implementation

def [](name)
	to_a.find { |guide| guide.name == name }
end

def related(guide)

Get the related guides (previous and next) for the given guide.

Signature

parameter guide Guide

The current guide.

returns Array(Guide | Nil, Guide | Nil)

A two-element array containing the previous and next guides.

Implementation

def related(guide)
	index = to_a.index { |g| g.name == guide.name }
	return [nil, nil] unless index
	
	previous_guide = index > 0 ? to_a[index - 1] : nil
	next_guide = index < to_a.size - 1 ? to_a[index + 1] : nil
	
	[previous_guide, next_guide]
end