Class: CoopAl::Library
- Inherits:
-
Object
- Object
- CoopAl::Library
- Includes:
- Singleton
- Defined in:
- lib/coop_al/library.rb
Overview
Library
Instance Method Summary collapse
- #add_adventure(adventure) ⇒ Object
- #adventure(name) ⇒ Object
- #adventure?(name) ⇒ Boolean
- #all_entries ⇒ Object
- #available_paths_from(path) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ Library
constructor
A new instance of Library.
- #path?(path) ⇒ Boolean
- #resolve(path) ⇒ Object
Constructor Details
#initialize ⇒ Library
Returns a new instance of Library.
10 11 12 |
# File 'lib/coop_al/library.rb', line 10 def initialize @adventures = {} end |
Instance Method Details
#add_adventure(adventure) ⇒ Object
18 19 20 21 |
# 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) ⇒ Object
27 28 29 |
# File 'lib/coop_al/library.rb', line 27 def adventure(name) @adventures[name] end |
#adventure?(name) ⇒ Boolean
23 24 25 |
# File 'lib/coop_al/library.rb', line 23 def adventure?(name) @adventures.key?(name) end |
#all_entries ⇒ Object
42 43 44 |
# 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) ⇒ Object
46 47 48 49 50 51 52 |
# 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? ⇒ Boolean
14 15 16 |
# File 'lib/coop_al/library.rb', line 14 def empty? @adventures.empty? end |
#path?(path) ⇒ Boolean
31 32 33 34 35 |
# 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) ⇒ Object
37 38 39 40 |
# 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 |