everyday-cli-utils 1.8.3 → 1.8.4
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.
- checksums.yaml +4 -4
- data/lib/everyday-cli-utils/ask.rb +10 -11
- data/lib/everyday-cli-utils/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d91beab1a1ce74081ab57134a8047ee6b6497f1
|
4
|
+
data.tar.gz: a071acf57054f2d6f81434b9fd5c9c48f09cffdd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67772a3f5c101be779fc63de1d3044180a7d1978214c4ba23e9f176236407b0958a7849d98aab5e6eec312b07a91f0225aef827e5cfba245e93f8a877d7b1b69
|
7
|
+
data.tar.gz: 4ec99aec1bcef43da7bcda9f5d687670c6f2de182b0a0f220c4641442787f062c7c5e0c3233c5ee030cb4f4d43af22c52207dd271627bae434a01fbab5f0971a
|
@@ -2,33 +2,32 @@ require 'readline'
|
|
2
2
|
|
3
3
|
module EverydayCliUtils
|
4
4
|
module Ask
|
5
|
-
def self
|
5
|
+
def self.setup_options(options)
|
6
6
|
mapped = []
|
7
7
|
options.each_with_index { |v, k|
|
8
|
-
mapped << "#{k+1}) #{v
|
8
|
+
mapped << "#{k + 1}) #{v}"
|
9
9
|
}
|
10
10
|
mapped.join("\n")
|
11
11
|
end
|
12
12
|
|
13
|
-
def self
|
13
|
+
def self.ask(question, options, &block)
|
14
14
|
val = '-1'
|
15
|
-
|
15
|
+
loop do
|
16
16
|
print "#{question}\n\n#{setup_options(options)}\n\n"
|
17
17
|
val = Readline.readline("Please enter your choice (1 - #{options.count}): ", true)
|
18
|
-
if !(val =~ /^\d+$/).nil? && (1..options.count).include?(val.to_i)
|
19
|
-
break
|
20
|
-
end
|
18
|
+
break if !(val =~ /^\d+$/).nil? && (1..options.count).include?(val.to_i)
|
21
19
|
print "\n\nYou must enter an integer between 1 and #{options.count}. Please try again.\n\n"
|
22
20
|
end
|
23
21
|
block.call(options[val.to_i - 1])
|
24
22
|
end
|
25
23
|
|
26
|
-
def self
|
27
|
-
resp = Readline.readline("#{question} (
|
28
|
-
|
24
|
+
def self.ask_yn(question, options = {}, &block)
|
25
|
+
resp = Readline.readline("#{question} ([y]es/[n]o) ", true)
|
26
|
+
val = resp.downcase == 'yes' || resp.downcase == 'y'
|
27
|
+
block.call(val) if !options[:only] || options[:only] == (val ? :yes : :no)
|
29
28
|
end
|
30
29
|
|
31
|
-
def self
|
30
|
+
def self.hash_to_options(hash, extra = [])
|
32
31
|
hash.keys + extra
|
33
32
|
end
|
34
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: everyday-cli-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Henderson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|