nutella 0.5 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/nutella/input.rb +25 -0
- data/lib/nutella/version.rb +1 -1
- metadata +3 -3
data/lib/nutella/input.rb
CHANGED
@@ -26,5 +26,30 @@ module Nutella
|
|
26
26
|
def input(prompt)
|
27
27
|
raw_input(prompt).strip
|
28
28
|
end
|
29
|
+
|
30
|
+
# Takes an integer input from the user. If the user does not enter a valid
|
31
|
+
# integer value, display the error and ask them again, unless +err_msg+ is
|
32
|
+
# <tt>nil</tt>, in which case it will not display any error message before
|
33
|
+
# asking again. If +repeat+ is set to false, it will only ask once, exiting
|
34
|
+
# and returning nil if the first attempt fails.
|
35
|
+
#
|
36
|
+
# @example Ask the user to input their age
|
37
|
+
# age = Nutella::int_input "Enter your age: "
|
38
|
+
#
|
39
|
+
# @param [String] prompt the message to display to the user
|
40
|
+
# @param [String, NilClass] err_msg the error to show the user if they
|
41
|
+
# should enter an invalid input
|
42
|
+
# @param [Boolean] repeat whether or not to continue prompting the user
|
43
|
+
# should their first input be unacceptable
|
44
|
+
# @return [Integer] the user's numeric input as an integer
|
45
|
+
def int_input(prompt, err_msg = "Please enter a number.", repeat = true)
|
46
|
+
str = ""
|
47
|
+
until str[/^-?\d+$/]
|
48
|
+
str = input prompt
|
49
|
+
puts err_msg unless str[/^-?\d+$/] || err_msg.nil?
|
50
|
+
return unless repeat
|
51
|
+
end
|
52
|
+
str.to_i
|
53
|
+
end
|
29
54
|
end
|
30
55
|
end
|
data/lib/nutella/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nutella
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.5.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
136
|
version: '0'
|
137
137
|
segments:
|
138
138
|
- 0
|
139
|
-
hash:
|
139
|
+
hash: 1434802851408277354
|
140
140
|
requirements: []
|
141
141
|
rubyforge_project:
|
142
142
|
rubygems_version: 1.8.24
|