Class: Konamio::Sequence::Requisition

Inherits:
Base
  • Object
show all
Includes:
KeyMap
Defined in:
lib/konamio/sequence/requisition.rb

Instance Method Summary collapse

Methods included from KeyMap

included, #sequence_for

Constructor Details

#initialize(options = {}) ⇒ Requisition

Returns a new instance of Requisition.

Parameters:

  • options (Hash) (defaults to: {})

    The group of options for the sequence requisition

Options Hash (options):

  • :speaker (Class) — default: Konamio::Prompt

    You could theoretically replace this with a class that responds to #new with an instance that responds to #execute! Not sure why you would.

  • :prompt (String) — default: "Enter konami code (or hit escape)"

    override with a falsey value to skip prompt dialog

  • :confirmation (String) — default: "Enter konami code (or hit escape)"

    override with a falsey value to skip confirmation dialog

  • :cancellation (String) — default: "Goodbye!"

    override with a falsey value to skip cancellation dialog

  • :sequence (Array, String) — default: [:up, :up, :down, :down, :left, :right, :left, :right, "B", "A"]


11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/konamio/sequence/requisition.rb', line 11

def initialize(options={})
  options = {
    input:        $stdin,
    output:       $stdout,
    listener:     Konamio::Sequence::Listener,
    speaker:      Konamio::Prompt,
    prompt:       "Enter konami code (or hit escape)",
    sequence:     [:up,:up,:down,:down,:left,:right,:left,:right,"B","A"],
    confirmation: "Good job, you.",
    cancellation: "Goodbye!"
  }.merge(options)

  load_options(:sequence, options)
end

Instance Method Details

#execute! {|sequence| ... } ⇒ Object

Returns Konamio::Result.

Yields:

  • (sequence)

    Gives the sequence to the block

Yield Returns:

  • The result of a block, if supplied

Returns:

  • Konamio::Result



30
31
32
33
34
35
36
37
# File 'lib/konamio/sequence/requisition.rb', line 30

def execute! &block
  prompt

  result = listen(@sequence)
  yield(@sequence) if block_given? && result.successful?

  result
end