consenter 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +36 -4
  3. data/lib/consenter/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 381f1b81e49de4299e3c390f79a9b3a0713496f4324549b32f7dab9cf546b6c0
4
- data.tar.gz: 213e9cb26ef6d8ea4f7141e2144ffeeef2eb7181d9bc3fba0be231ebdc5e9c65
3
+ metadata.gz: 6048b379d9b300a7eb28c55a302977f16fe51a7fdddacd626f4208babccf8607
4
+ data.tar.gz: 74af2f204d90a412004dde7c57e65da3b28f0fa64785462208ea7ffc803bed28
5
5
  SHA512:
6
- metadata.gz: 43511490721fced00095c3fcbe9c99471ff66a112058c451755e9f64dd50da486092893da23070888e255a243be4ca7ea2c9a7bb92275b40bb193f30d25e8009
7
- data.tar.gz: 82556a9705b39381c507fca95a5f05274e73c8253430007db1badf9cd84e5ff23371f86d654707349dafa478159f9c7e07fcbfe69d9d29217107393a55b353c4
6
+ metadata.gz: d5192bc8fd68878b10eba5597ebffc488b8249dc0709b64399517537262b59f804bb2a4ec05176d92f0aea46bdbd40ace1fb4c08d7a26c5c1c317a1844a20270
7
+ data.tar.gz: d7b85da181baf6ca15d446cc394a96af38f4bd73c899a0a4acdfca5d8b00d495faceed1a492c9359b25219c8cbdb22642b16bd257574d8bddb2377e737cd77c4
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Consenter
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/consenter`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Write usage instructions here
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
 
@@ -1,3 +1,3 @@
1
1
  class Consenter
2
- VERSION = '1.0.1'.freeze
2
+ VERSION = '1.0.2'.freeze
3
3
  end
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.1
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-04 00:00:00.000000000 Z
11
+ date: 2018-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler