Class Annoy
In: lib/annoy.rb
Parent: Object

Annoy

Like your annoying friend that asks you questions all the time.

Rudy uses Annoy to present the user with a simple question before continuing with a destructive action.

Methods

Classes and Modules

Class Annoy::GiveUp

Attributes

answer  [RW] 
factor  [RW] 
flavor  [RW] 
period  [RW] 
system  [RW] 
writer  [RW] 

Public Class methods

Runs a challenge with the message, "Are you sure?" See: Annoy.challenge?

Prints a question to writer and waits for a response on STDIN. It checks whether STDIN is connected a tty so it doesn‘t block on gets when there‘s no human around to annoy. It will return TRUE when STDIN is NOT connected to a tty (when STDIN.tty? returns false).

  • msg The message to print. Default: "Please confirm."

Returns true when the answer is correct, otherwise false.

Tells annoy to prompt for a response.

Calling this method tells Annoy to not prompt for a response. All questions will return true.

Get a response from the user. Returns the string as typed by the user with extraneous whitespace removed.

  • msg (required) text to display to user
  • echo (optional) character to display as user types. Used for hiding passwords.
  • period (optional) amount of time to wait.

NOTE: Annoy uses Highline to get user responses. If msg ends with a space character, Highline will not print a new line. If there is no space character Highline will print a new line.

    Annoy.get_user_input("Password?")   # => Password?
                                        # => 'user types here'

    Annoy.get_user_input("Password? ")  # => Password? 'user types here'
  • factor annoyance factor, one of :low (default), :medium, :high, :insane
  • flavor annoyance flavor, one of :rand (default), :numeric, string
  • writer an IO object to write to. Default: STDERR
  • period the amount of time to wait in seconds. Default: 60
  • Generates a rudimentary numeric equation in the form: (Integer OPERATOR Integer).
  • Returns [equation, answer]

Prints a question to writer and waits for a response on STDIN. It checks whether STDIN is connected a tty so it doesn‘t block on gets. when there‘s no human around to annoy. It will return TRUE when STDIN is NOT connected to a tty or if writer is nil.

  • msg The question to pose to the user
  • regexp The regular expression to match the answer.

Runs a challenge with the message, "Proceed?" See: Annoy.challenge?

A wrapper for string_question and numberic_question

Returns true of Annoy is in skip mode

Generates a random string

Display msg for period seconds. NOTE: msg should be a short, single line. This is a naive approach which simply overwrites the current line.

Public Instance methods

See: Annoy.challenge? Uses the value of @flavor, @factor, and @writer

See: Annoy.pose_question Uses the value of @writer

Generates and returns a question. The correct response is available as +@answer+.

[Validate]