Class: Mousevc::Input
- Inherits:
-
Object
- Object
- Mousevc::Input
- 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.
nil- @@data =
Returns the user input data retrieved via
Input.prompt. nil- @@prompts =
Returns 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. nil
Instance Attribute Summary collapse
-
#appearance ⇒ Symbol
The symbol name of the prompt appearance to use from
Input.prompts. -
#data ⇒ String
readonly
The user input data retrieved via
Input.prompt. -
#notice ⇒ String
The notice message.
-
#prompts ⇒ Hash
readonly
A hash of prompts available for use in
Input.prompt.
Class Method Summary collapse
-
.appearance ⇒ Symbol
The symbol name of the current prompt appearance.
-
.appearance=(value) ⇒ Object
Set the default appearance for the prompt.
-
.clear(*args) ⇒ Object
Clears all or a list of class variables by setting them to
nil. -
.clear? ⇒ Boolean
Check if the user is tring to clear the input data.
-
.data ⇒ String
Get the current value of user input retrieved via
Input.prompt. -
.notice ⇒ String
Get the notice message.
-
.notice=(value) ⇒ Object
Set the notice message.
-
.notice? ⇒ Boolean
Check if a notice message exists.
-
.prompt(appearance = nil) ⇒ Object
Prompts the user for input using
gets.stripOnce input is submitted it will be available viaInput.data. -
.prompts ⇒ Hash
A hash of the currently available prompt appearances.
-
.quit? ⇒ Boolean
Check if the user is trying to quit the application.
-
.reset? ⇒ Boolean
Check if the user is trying to reset the application.
Instance Attribute Details
#appearance ⇒ Symbol
Returns the symbol name of the prompt appearance to use from Input.prompts.
30 |
# File 'lib/mousevc/input.rb', line 30 @@appearance = nil |
#data ⇒ String (readonly)
Returns the user input data retrieved via Input.prompt.
18 |
# File 'lib/mousevc/input.rb', line 18 @@data = nil |
#notice ⇒ String
Returns the notice message.
12 |
# File 'lib/mousevc/input.rb', line 12 @@notice = nil |
#prompts ⇒ Hash (readonly)
Returns a hash of prompts available for use in Input.prompt.
24 |
# File 'lib/mousevc/input.rb', line 24 @@prompts = {:default => '>'} |
Class Method Details
.appearance ⇒ Symbol
Returns 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
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
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
146 147 148 |
# File 'lib/mousevc/input.rb', line 146 def self.clear? ['c', 'clear'].include?(@@data) end |
.data ⇒ String
Get the current value of user input retrieved via Input.prompt
110 111 112 |
# File 'lib/mousevc/input.rb', line 110 def self.data @@data end |
.notice ⇒ String
Get 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
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
119 120 121 |
# File 'lib/mousevc/input.rb', line 119 def self.notice? ! @@notice.to_s.empty? end |
.prompt(appearance = nil) ⇒ Object
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
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 |
.prompts ⇒ Hash
Returns 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
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
128 129 130 |
# File 'lib/mousevc/input.rb', line 128 def self.reset? ['r', 'reset'].include?(@@data) end |