class Guides
A collection of guides with navigation and lookup capabilities.
Definitions
def initialize(base, links)
Initialize the guides collection.
Signature
-
parameter
baseBase The base instance for the project.
-
parameter
linksObject 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
guideGuide
-
parameter
-
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
nameString The guide name.
-
returns
Guide | Nil
Implementation
def [](name)
to_a.find { |guide| guide.name == name }
end