README.md in interactive-0.1.0 vs README.md in interactive-0.2.0
- old
+ new
@@ -21,10 +21,11 @@
$ gem install interactive
## Usage
+### Questions With Lazy Shortcut Explanations
If you want to ask a user a question expecting certain answers:
```ruby
question = Interactive::Question.new do |ques|
ques.question = "Which item do you want to use?"
@@ -47,33 +48,65 @@
# do stuff if user responded with "q", etc.
end
end
```
-That will ask the question appended by the shortcuts:
+That will ask the question appended by the shortcuts (without full explanation):
-```ruby
-# => "Which item do you want to use? [1/2/3/c/q]"
+```sh
+Which item do you want to use? [1/2/3/c/q]
```
If the response is valid:
-```ruby
-$ a
-# => response.add? will return true
+```sh
+$ a # response.add? will return true
```
If the response is invalid, it prints out the question and goes into detail as
to what the shortcuts stand for:
-```ruby
+```sh
$ bad-response
-# => Which item do you want to use? [1/2/3/c/q]
-# => 1 -- 1
-# => 2 -- 2
-# => 3 -- 3
-# => c -- cancel
-# => q -- quit
+
+Which item do you want to use? [1/2/3/c/q]
+ 1 -- 1
+ 2 -- 2
+ 3 -- 3
+ c -- cancel
+ q -- quit
+```
+
+### Questions With Eager Shortcut Explanations
+
+Providing an array of options to the options array will trigger the shortcut
+explanation right after asking the question:
+
+```ruby
+
+options_list = ["/some/path", "/some/other/path"]
+iq = Interactive::Question.new do |q|
+ q.question = "Which path do you want to use?"
+ q.options = [options_list, :cancel]
+end
+
+iq.ask_and_wait_for_valid_response do |response|
+ if response.whole_number?
+ # response.to_i will convert the response string to an integer.
+ # useful for getting the index (i.e. options_list[response.to_i])
+ elsif response.cancel?
+ # do stuff to cancel...
+ end
+end
+```
+
+This will ask the question and show the explanation eagerly:
+
+```sh
+Which path do you want to use? [0/1/c]
+ 0 -- /some/path
+ 1 -- /some/other/path
+ c -- cancel
```
## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.