Class: Fictive::Story
- Inherits:
-
Object
- Object
- Fictive::Story
- Defined in:
- lib/fictive/story.rb
Class Method Summary collapse
Instance Method Summary collapse
- #choose_path(path) ⇒ Object
- #has_next? ⇒ Boolean
-
#initialize(scenes) ⇒ Story
constructor
A new instance of Story.
- #next ⇒ Object
Constructor Details
#initialize(scenes) ⇒ Story
Returns a new instance of Story.
37 38 39 40 41 42 43 44 45 |
# File 'lib/fictive/story.rb', line 37 def initialize(scenes) @scenes = scenes @scenes_index = {} @scenes.each_with_index do |scene, id| @scenes_index[scene.path] = id end @index = 0 end |
Class Method Details
.demo ⇒ Object
30 31 32 33 34 35 |
# File 'lib/fictive/story.rb', line 30 def self.demo self.new([ Scene.new({path: 'hello', choices: [Choice.new({path: 'goodbye'})]}, 'Hello world'), Scene.new({path: 'goodbye'}, 'Goodbye world') ]) end |
Instance Method Details
#choose_path(path) ⇒ Object
55 56 57 |
# File 'lib/fictive/story.rb', line 55 def choose_path(path) @index = @scenes_index[path] end |
#has_next? ⇒ Boolean
47 48 49 |
# File 'lib/fictive/story.rb', line 47 def has_next? !@scenes.at(@index).nil? && !@scenes.at(@index + 1).nil? end |
#next ⇒ Object
51 52 53 |
# File 'lib/fictive/story.rb', line 51 def next @scenes.at(@index) end |