console-glitter 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/lib/console-glitter/version.rb +1 -1
- data/lib/console-glitter.rb +28 -11
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
MzkzNmEwZjE4OGY5ZmMxNTAwN2I5MGVmODliZDM3YzFlNWZiZTA2Mw==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 33104b9e9e88b3aa31b5e7435f4a3e89850b876e
|
4
|
+
data.tar.gz: 0136e1d73e74034ce026bb00cab07b5d2193ae00
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
ZjMzMjYwMWEzYTRiYmE2ZWZlNDE2ZmY3MjM1NTgxZWZkYWYwZDRjZjEzOTk5
|
11
|
-
ZmNhNmVmMmQzZTRlZmE4NzhmYzYyMjY4OGQ5YTU5Njg0Y2Y4Y2M=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NTM2YzAwNmI0NTZiZjc2YWU5Y2E5OGQxNTU1ZjAwMTA1YWM4NmVkYTIxNWU0
|
14
|
-
NGJlZDBlZGMyYzBiNjJmM2RlY2RjMDQ1MTc0ZGVkNTZjMDljNWNjNjQyNGEy
|
15
|
-
NjYzZGYyZmMxOTk2Mzk3YjdjNDAzMGNiZmE2MWU3OGEwZjIzZWE=
|
6
|
+
metadata.gz: 0799c8ec2726665bbf64adc5aeb443b67fd0c87d7e79962446db02d665f7b9cdbac87aefba73c6f0f5fa16fbfc318891cd3a814efe9b9073712fb07941d7edee
|
7
|
+
data.tar.gz: 9068a4dfe4e21084c1f87cfa66eff438a008680a78b5591d8e7013f637086ccabef7f221103d3e0ed2a1ec73cc5a555a93cdaaef6a327369bcc63c726f228e33
|
data/lib/console-glitter.rb
CHANGED
@@ -18,13 +18,16 @@ module ConsoleGlitter
|
|
18
18
|
# will be rejected.
|
19
19
|
# :valid_answers - An Array containing all valid responses. If
|
20
20
|
# this is empty, any answer will be accepted
|
21
|
-
# (
|
21
|
+
# (unless empty answers are disallowed as
|
22
|
+
# specified above). Valid responses may be
|
23
|
+
# any class with a match method such as
|
24
|
+
# Strings or Regexps.
|
22
25
|
#
|
23
26
|
# Returns a String containing the answer provided by the user.
|
24
27
|
def prompt(question, options = {})
|
25
28
|
default = options[:default_answer].to_s
|
26
29
|
allow_empty = options[:allow_empty]
|
27
|
-
valid = options[:valid_answers]
|
30
|
+
valid = regexify_answers(options[:valid_answers])
|
28
31
|
|
29
32
|
default_display = " [#{default.strip}]" unless default.empty?
|
30
33
|
question.strip!
|
@@ -38,7 +41,7 @@ module ConsoleGlitter
|
|
38
41
|
if answer.empty?
|
39
42
|
answer = nil unless allow_empty
|
40
43
|
elsif valid.any?
|
41
|
-
answer = nil unless valid.
|
44
|
+
answer = nil unless valid.map { |valid| answer.match(valid) }.any?
|
42
45
|
end
|
43
46
|
end
|
44
47
|
|
@@ -54,14 +57,8 @@ module ConsoleGlitter
|
|
54
57
|
#
|
55
58
|
# Returns true or false corresponding to Y or N answer respectively.
|
56
59
|
def prompt_yn(question, args = {})
|
57
|
-
args[:valid_answers] = []
|
58
|
-
|
59
|
-
|
60
|
-
until answer =~ /^[yn]/i
|
61
|
-
answer = prompt(question, args)
|
62
|
-
end
|
63
|
-
|
64
|
-
/^n/i.match(answer).nil?
|
60
|
+
args[:valid_answers] = [/^[yn]/i]
|
61
|
+
/^n/i.match(prompt(question, args)).nil?
|
65
62
|
end
|
66
63
|
|
67
64
|
# Public: Render a "spinner" on the command line and yield to a block,
|
@@ -149,4 +146,24 @@ module ConsoleGlitter
|
|
149
146
|
grid << grid_rule
|
150
147
|
end
|
151
148
|
end
|
149
|
+
|
150
|
+
private
|
151
|
+
|
152
|
+
# Internal: Generate Regexps for any String in an array to be used in order
|
153
|
+
# to match against user input. Strings are expected to indicate exact
|
154
|
+
# matches desired.
|
155
|
+
#
|
156
|
+
# valid_answers - Array containing Objects against which user input may be
|
157
|
+
# matched.
|
158
|
+
#
|
159
|
+
# Returns an Array of Regexps.
|
160
|
+
def regexify_answers(valid_answers)
|
161
|
+
valid_answers.to_a.map do |answer|
|
162
|
+
if answer.is_a?(String)
|
163
|
+
Regexp.new("^#{Regexp.escape(answer)}$")
|
164
|
+
else
|
165
|
+
answer
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
152
169
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: console-glitter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Wuest
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Tools for building nice looking CLI applications
|
14
14
|
email: chris@chriswuest.com
|
@@ -29,12 +29,12 @@ require_paths:
|
|
29
29
|
- lib
|
30
30
|
required_ruby_version: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- -
|
32
|
+
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: '0'
|
35
35
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- -
|
37
|
+
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '0'
|
40
40
|
requirements: []
|