Class: Mousevc::Input

Inherits:
Object
  • Object
show all
Defined in:
lib/mousevc/input.rb

Overview

A globally accessible class to allow access to user input and provide input specific notices.

Constant Summary collapse

@@notice =

Returns the notice message

Returns:

  • (String)

    the notice message

nil
@@data =

Returns the user input data retrieved via Input.prompt

Returns:

  • (String)

    the user input data retrieved via Input.prompt

nil
@@prompts =

Returns a hash of prompts available for use in Input.prompt

Returns:

  • (Hash)

    a hash of prompts available for use in Input.prompt

{:default => '>'}
@@appearance =

Returns the symbol name of the prompt appearance to use from Input.prompts

Returns:

  • (Symbol)

    the symbol name of the prompt appearance to use from Input.prompts

nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#appearanceSymbol

Returns the symbol name of the prompt appearance to use from Input.prompts

Returns:

  • (Symbol)

    the symbol name of the prompt appearance to use from Input.prompts


30
# File 'lib/mousevc/input.rb', line 30

@@appearance = nil

#dataString (readonly)

Returns the user input data retrieved via Input.prompt

Returns:

  • (String)

    the user input data retrieved via Input.prompt


18
# File 'lib/mousevc/input.rb', line 18

@@data = nil

#noticeString

Returns the notice message

Returns:

  • (String)

    the notice message


12
# File 'lib/mousevc/input.rb', line 12

@@notice = nil

#promptsHash (readonly)

Returns a hash of prompts available for use in Input.prompt

Returns:

  • (Hash)

    a hash of prompts available for use in Input.prompt


24
# File 'lib/mousevc/input.rb', line 24

@@prompts = {:default => '>'}

Class Method Details

.appearanceSymbol

Returns the symbol name of the current prompt appearance

Returns:

  • (Symbol)

    the symbol name of the current prompt appearance


35
36
37
# File 'lib/mousevc/input.rb', line 35

def self.appearance
	@@appearance
end

.appearance=(value) ⇒ Object

Set the default appearance for the prompt

Parameters:

  • value (Symbol)

    the symbol name of the appearance to use from Input.prompts


44
45
46
# File 'lib/mousevc/input.rb', line 44

def self.appearance=(value)
	@@appearance = value
end

.clear(*args) ⇒ Object

Clears all or a list of class variables by setting them to nil

Parameters:

  • args (Symbol)

    a symbol list of class variables to clear


53
54
55
56
57
58
59
60
61
62
63
# File 'lib/mousevc/input.rb', line 53

def self.clear(*args)
	if args.empty?
		args = [
			:notice,
			:data,
			:prompts,
			:appearance
		]
	end
	to_defaults(args)
end

.clear?Boolean

Check if the user is tring to clear the input data

Returns:

  • (Boolean)

    true if Input.data is c or clear


146
147
148
# File 'lib/mousevc/input.rb', line 146

def self.clear?
	['c', 'clear'].include?(@@data)
end

.dataString

Get the current value of user input retrieved via Input.prompt

Returns:

  • (String)

    the data


110
111
112
# File 'lib/mousevc/input.rb', line 110

def self.data
	@@data
end

.noticeString

Get the notice message

Returns:

  • (String)

    the notice message


92
93
94
# File 'lib/mousevc/input.rb', line 92

def self.notice
	@@notice
end

.notice=(value) ⇒ Object

Set the notice message. This is a good place to put error messages corresponding to user input

Parameters:

  • value (String)

    the notice message


101
102
103
# File 'lib/mousevc/input.rb', line 101

def self.notice=(value)
	@@notice = value
end

.notice?Boolean

Check if a notice message exists

Returns:

  • (Boolean)

    false if notice message is empty


119
120
121
# File 'lib/mousevc/input.rb', line 119

def self.notice?
	! @@notice.to_s.empty?
end

.prompt(appearance = nil) ⇒ Object

Note:

Calling this method will stop all execution until the user submits input

Prompts the user for input using gets.strip Once input is submitted it will be available via Input.data

Parameters:

  • appearance (Symbol) (defaults to: nil)

    the symbol name of the prompt the use from Input.prompts

    • If an appearance is not specified it uses :default


74
75
76
77
78
# File 'lib/mousevc/input.rb', line 74

def self.prompt(appearance=nil)
	appearance = pick(appearance)
	print "\n#{appearance} "
	@@data = $stdin.gets.to_s.strip
end

.promptsHash

Returns a hash of the currently available prompt appearances

Returns:

  • (Hash)

    a hash of the currently available prompt appearances


83
84
85
# File 'lib/mousevc/input.rb', line 83

def self.prompts
	@@prompts
end

.quit?Boolean

Check if the user is trying to quit the application

Returns:

  • (Boolean)

    true if Input.data is q, quit, or exit


137
138
139
# File 'lib/mousevc/input.rb', line 137

def self.quit?
	['q', 'quit', 'exit'].include?(@@data)
end

.reset?Boolean

Check if the user is trying to reset the application

Returns:

  • (Boolean)

    true if Input.data is r or reset


128
129
130
# File 'lib/mousevc/input.rb', line 128

def self.reset?
	['r', 'reset'].include?(@@data)
end