Class: Gamefic::Scene::YesOrNo
- Defined in:
- lib/gamefic/scene/yes_or_no.rb
Overview
Prompt the user to answer “yes” or “no”. The scene will accept variations like “YES” or “n” and normalize the answer to “yes” or “no” in the finish block. After the scene is finished, the :active scene will be cued if no other scene has been prepared or cued.
Instance Attribute Summary collapse
-
#invalid_message ⇒ String
The message sent to the user for an invalid answer, i.e., the input could not be resolved to either Yes or No.
Attributes inherited from Base
#actor, #data, #input, #prompt, #type
Instance Method Summary collapse
- #finish ⇒ Object
-
#no? ⇒ Boolean
True if the actor’s answer is No.
- #post_initialize ⇒ Object
- #state ⇒ Object
-
#yes? ⇒ Boolean
True if the actor’s answer is Yes.
Methods inherited from Base
#[], #finished?, #initialize, #on_finish, on_start, #start, start_block, subclass, #tracked=, #tracked?, tracked?, #update
Constructor Details
This class inherits a constructor from Gamefic::Scene::Base
Instance Attribute Details
#invalid_message ⇒ String
The message sent to the user for an invalid answer, i.e., the input could not be resolved to either Yes or No.
35 36 37 |
# File 'lib/gamefic/scene/yes_or_no.rb', line 35 def ||= 'Please enter Yes or No.' end |
Instance Method Details
#finish ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/gamefic/scene/yes_or_no.rb', line 39 def finish if yes? or no? super else actor.tell end end |
#no? ⇒ Boolean
True if the actor’s answer is No. Any answer beginning with letter N is considered No.
27 28 29 |
# File 'lib/gamefic/scene/yes_or_no.rb', line 27 def no? input.to_s[0,1].downcase == 'n' or input.to_i == 2 end |
#post_initialize ⇒ Object
10 11 12 13 |
# File 'lib/gamefic/scene/yes_or_no.rb', line 10 def post_initialize self.type = 'YesOrNo' self.prompt = 'Yes or No:' end |
#state ⇒ Object
47 48 49 |
# File 'lib/gamefic/scene/yes_or_no.rb', line 47 def state super.merge options: ['Yes', 'No'] end |
#yes? ⇒ Boolean
True if the actor’s answer is Yes. Any answer beginning with letter Y is considered Yes.
19 20 21 |
# File 'lib/gamefic/scene/yes_or_no.rb', line 19 def yes? input.to_s[0,1].downcase == 'y' or input.to_i == 1 end |