consenter 1.0.1 → 1.0.2
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/README.md +36 -4
- data/lib/consenter/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6048b379d9b300a7eb28c55a302977f16fe51a7fdddacd626f4208babccf8607
|
4
|
+
data.tar.gz: 74af2f204d90a412004dde7c57e65da3b28f0fa64785462208ea7ffc803bed28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5192bc8fd68878b10eba5597ebffc488b8249dc0709b64399517537262b59f804bb2a4ec05176d92f0aea46bdbd40ace1fb4c08d7a26c5c1c317a1844a20270
|
7
|
+
data.tar.gz: d7b85da181baf6ca15d446cc394a96af38f4bd73c899a0a4acdfca5d8b00d495faceed1a492c9359b25219c8cbdb22642b16bd257574d8bddb2377e737cd77c4
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# Consenter
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
`Enumerable#each_consented` is an opinionated but idiomatic way to filter elements of an `Enumerable` by user consent.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -22,7 +20,41 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
23
|
+
`Enumerable#each_consented` works exactly like `Enumerable#each`, but before yielding each element of the collection, it prompts the user (via the `IO#console`, ie. `/dev/tty`) for confirmation, using the prompt provided as an argument.
|
24
|
+
|
25
|
+
A simple example: `puts 0.upto(9).each_consented('Pick %d?').sum` will print out the sum of all numbers between `0` and `9` which the user has picked.
|
26
|
+
|
27
|
+
The following example shows the interaction:
|
28
|
+
|
29
|
+
* each element is passed to `Kernel#format` to generate the customizable prompt
|
30
|
+
* answering `y` will cause the current element to be yielded
|
31
|
+
* answering `Y` will cause the current element and all remaining ones to be yielded
|
32
|
+
* answering `n` will cause the current element to be skipped
|
33
|
+
* answering `N` will cause the current element and all remaining ones to be skipped
|
34
|
+
* answering `q` will cause the iteration to be aborted
|
35
|
+
* answering `?` will print out a help message
|
36
|
+
* answering anything else will also print out the help message
|
37
|
+
|
38
|
+
```
|
39
|
+
$ ruby -r consenter -e "puts 0.upto(9).each_consented('Pick %d?').sum"
|
40
|
+
Pick 0? [y,n,Y,N,q,?] ?
|
41
|
+
y - yes to this
|
42
|
+
n - no to this
|
43
|
+
Y - yes to this and all remaining
|
44
|
+
N - no to this and all remaining
|
45
|
+
q - quit
|
46
|
+
? - help
|
47
|
+
Pick 0? [y,n,Y,N,q,?] y
|
48
|
+
Pick 1? [y,n,Y,N,q,?] n
|
49
|
+
Pick 2? [y,n,Y,N,q,?] n
|
50
|
+
Pick 3? [y,n,Y,N,q,?] n
|
51
|
+
Pick 4? [y,n,Y,N,q,?] y
|
52
|
+
Pick 5? [y,n,Y,N,q,?] y
|
53
|
+
Pick 6? [y,n,Y,N,q,?] N
|
54
|
+
9
|
55
|
+
$ _
|
56
|
+
```
|
57
|
+
|
26
58
|
|
27
59
|
## Development
|
28
60
|
|
data/lib/consenter/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: consenter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Vandenberk
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|