Class: Fictive::Story
- Inherits:
-
Object
- Object
- Fictive::Story
- Defined in:
- lib/fictive/story.rb
Class Method Summary collapse
Instance Method Summary collapse
- #choose_path(id) ⇒ Object
- #has_next? ⇒ Boolean
-
#initialize(passages) ⇒ Story
constructor
A new instance of Story.
- #next ⇒ Object
Constructor Details
#initialize(passages) ⇒ Story
Returns a new instance of Story.
10 11 12 13 14 15 16 17 18 |
# File 'lib/fictive/story.rb', line 10 def initialize(passages) @passages = passages @passages_index = {} @passages.each_with_index do |passage, id| @passages_index[passage.id] = id end @index = 0 end |
Class Method Details
.demo ⇒ Object
3 4 5 6 7 8 |
# File 'lib/fictive/story.rb', line 3 def self.demo self.new([ Passage.new({id: 'hello', choices: [Choice.new({id: 'goodbye'})]}, 'Hello world'), Passage.new({id: 'goodbye'}, 'Goodbye world') ]) end |
Instance Method Details
#choose_path(id) ⇒ Object
28 29 30 |
# File 'lib/fictive/story.rb', line 28 def choose_path(id) @index = @passages_index[id] end |
#has_next? ⇒ Boolean
20 21 22 |
# File 'lib/fictive/story.rb', line 20 def has_next? !@passages.at(@index).nil? && !@passages.at(@index + 1).nil? end |
#next ⇒ Object
24 25 26 |
# File 'lib/fictive/story.rb', line 24 def next @passages.at(@index) end |