From 23a3bb799ead9e2b37240762c76d3b300596d6c0 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sun, 11 Jan 2015 22:15:54 -0500 Subject: d: utils_response, rely on module (remove class) extend module * update a couple of affected files --- lib/sisu/current/utils_response.rb | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'lib/sisu/current/utils_response.rb') diff --git a/lib/sisu/current/utils_response.rb b/lib/sisu/current/utils_response.rb index 6f30437c..c47fab2e 100644 --- a/lib/sisu/current/utils_response.rb +++ b/lib/sisu/current/utils_response.rb @@ -69,5 +69,45 @@ module SiSU_Response ans end end + def query + def selections_available_(selections=:strict) + short_options=(selections == :strict) ? '' : '; [ynqx]' + %{'yes', 'no', 'quit' or 'exit'#{short_options}} + end + 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__ -- cgit v1.2.3