README.md in interactive-0.2.0 vs README.md in interactive-0.3.0
- old
+ new
@@ -21,25 +21,67 @@
$ gem install interactive
## Usage
+### Questions Without any Options
+If you want to ask a user a question accepting all answers:
+
+```ruby
+require 'interactive'
+include 'interactive'
+
+question = Question.new do |q|
+ q.question = "What is your api token password?"
+end
+
+question.ask do |response|
+ # response is an object that responds to string methods
+ puts response.split
+end
+```
+
+This will ask:
+
+```ruby
+=> What are your project ids?
+```
+
+You can respond like so, for example:
+
+```ruby
+$ 123someid hello4545 12992hhoo
+```
+
+That will give us the following:
+
+```ruby
+=> 123someid
+ hello4545
+ 12992hhoo
+```
+
### 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?"
- ques.options = [1..3, :cancel, :quit]
+require 'interactive'
+include 'interactive'
+
+question = Question.new do |q|
+ q.question = "Which item do you want to use?"
+ q.options = [1..3, :cancel, :quit]
end
```
You can run the loop and wait for a valid response and do query methods on the
response:
```ruby
-question.ask_and_wait_for_valid_response do |response|
+question.ask do |response|
if response.whole_num_1?
# do stuff if user responded with "1"
elsif response.whole_num?
# do stuff if user responded with "1", "2", or "3"
elsif response.cancel?
@@ -80,17 +122,21 @@
Providing an array of options to the options array will trigger the shortcut
explanation right after asking the question:
```ruby
+require 'interactive'
+include 'interactive'
+# ...
+
options_list = ["/some/path", "/some/other/path"]
-iq = Interactive::Question.new do |q|
+iq = 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|
+iq.ask 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...