aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/develop/utils_response.rb
diff options
context:
space:
mode:
authorRalph Amissah <ralph@amissah.com>2015-01-11 22:15:54 -0500
committerRalph Amissah <ralph@amissah.com>2015-01-19 23:46:16 -0500
commit23a3bb799ead9e2b37240762c76d3b300596d6c0 (patch)
tree4ac37278270617293495fada61abdc8fadfc9902 /lib/sisu/develop/utils_response.rb
parentd: utils_response, ease selection options (diff)
d: utils_response, rely on module (remove class) extend module
* update a couple of affected files
Diffstat (limited to 'lib/sisu/develop/utils_response.rb')
-rw-r--r--lib/sisu/develop/utils_response.rb64
1 files changed, 51 insertions, 13 deletions
diff --git a/lib/sisu/develop/utils_response.rb b/lib/sisu/develop/utils_response.rb
index 4603646e..a29f2fcd 100644
--- a/lib/sisu/develop/utils_response.rb
+++ b/lib/sisu/develop/utils_response.rb
@@ -55,22 +55,60 @@
=end
module SiSU_Response
- class Response
- def available_selections_
- %{'yes', 'no', 'quit' or 'exit'; [ynqx]}
+ def available_selections_
+ %{'yes', 'no', 'quit' or 'exit'; [ynqx]}
+ end
+ def response?(ask)
+ response='redo'
+ print ask + %{ [#{available_selections_}]: }
+ response=File.new('/dev/tty').gets.strip
+ case response
+ when /^(?:y|yes)$/ then true
+ when /^(?:n|no)$/ then false
+ when /^(?:[qx]|quit|exit)$/ then exit
+ else puts %{[please type: #{available_selections_}]}
+ response?(ask)
+ end
+ end
+ def query
+ def selections_available_(selections=:strict)
+ short_options=(selections == :strict) ? '' : '; [ynqx]'
+ %{'yes', 'no', 'quit' or 'exit'#{short_options}}
end
- def response?(ask)
- response='redo'
- print ask + %{ [#{available_selections_}]: }
- response=File.new('/dev/tty').gets.strip
- case response
- when /^(?:y|yes)$/ then true
- when /^(?:n|no)$/ then false
- when /^(?:[qx]|quit|exit)$/ then exit
- else puts %{[please type: #{available_selections_}]}
- response?(ask)
+ def selection_options
+ def response_strict(resp)
+ case resp
+ when /^(?:yes)$/ then true
+ when /^(?:no)$/ then false
+ when /^(?:quit|exit)$/ then exit
+ else
+ puts %{response was: #{resp}}
+ puts %{[please type to select: #{selections_available_(:strict)}]}
+ answer?('',:strict)
+ end
end
+ def response_short(resp)
+ case resp
+ when /^(?:y|yes)$/ then true
+ when /^(?:n|no)$/ then false
+ when /^(?:[qx]|quit|exit)$/ then exit
+ else
+ puts %{response was: #{resp}}
+ puts %{[please type to select: #{selections_available_(:short)}]}
+ answer?('',:short)
+ end
+ end
+ self
+ end
+ def answer?(ask,selections=:strict)
+ resp='redo'
+ print ask + %{PROCEED? [#{selections_available_(selections)}]: }
+ resp=File.new('/dev/tty').gets.strip
+ (selections==:strict) \
+ ? selection_options.response_strict(resp)
+ : selection_options.response_short(resp)
end
+ self
end
end
__END__