class CoopAl::Library

Library

Public Class Methods

new() click to toggle source
# File lib/coop_al/library.rb, line 10
def initialize
  @adventures = {}
end

Public Instance Methods

add_adventure(adventure) click to toggle source
# File lib/coop_al/library.rb, line 18
def add_adventure(adventure)
  raise Exception, 'Duplicate adventure' if @adventures.key?(adventure.name)
  @adventures[adventure.name] = adventure
end
adventure(name) click to toggle source
# File lib/coop_al/library.rb, line 27
def adventure(name)
  @adventures[name]
end
adventure?(name) click to toggle source
# File lib/coop_al/library.rb, line 23
def adventure?(name)
  @adventures.key?(name)
end
all_entries() click to toggle source
# File lib/coop_al/library.rb, line 42
def all_entries
  @adventures.values.inject([]) { |a, e| a + e.all_entries }
end
available_paths_from(path) click to toggle source
# File lib/coop_al/library.rb, line 46
def available_paths_from(path)
  return all_entries if path.root?
  current_chapter = resolve(path)
  paths = current_chapter.links
  paths << Path.root if current_chapter.links_to_downtime?
  paths
end
empty?() click to toggle source
# File lib/coop_al/library.rb, line 14
def empty?
  @adventures.empty?
end
path?(path) click to toggle source
# File lib/coop_al/library.rb, line 31
def path?(path)
  raise Exception, "Cannot resolve relative path (#{path})" if path.relative?
  return false unless @adventures.key?(path.adventure)
  @adventures[path.adventure].chapter?(path.chapter)
end
resolve(path) click to toggle source
# File lib/coop_al/library.rb, line 37
def resolve(path)
  raise Exception, "Adventure (#{path.adventure}) not found" unless @adventures.key?(path.adventure)
  @adventures[path.adventure].chapter(path.chapter)
end