Sha256: eeab2768849280fc68c6df34b0133169de5587902a1b0695b8b8fa5eea374f64

Contents?: true

Size: 853 Bytes

Versions: 2

Compression:

Stored size: 853 Bytes

Contents

module Gamefic

  # 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.
  #
  class Scene::YesOrNo < Scene::Custom
    def post_initialize
      self.type = 'YesOrNo'
      self.prompt = 'Yes or No?'
    end

    def yes?
      input.to_s[0,1].downcase == 'y'
    end

    def no?
      input.to_s[0,1].downcase == 'n'
    end

    def invalid_message
      @invalid_message ||= 'Please enter Yes or No.'
    end

    def prompt
      @prompt ||= 'Yes or No?'
    end

    def finish
      if yes? or no?
        super
      else
        actor.tell invalid_message
      end
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gamefic-1.7.0 lib/gamefic/scene/yes_or_no.rb
gamefic-1.6.0 lib/gamefic/scene/yes_or_no.rb