diff options
author | Abinoam Praxedes Marques Jr <abinoam@gmail.com> | 2015-05-31 00:35:52 -0300 |
---|---|---|
committer | Abinoam Praxedes Marques Jr <abinoam@gmail.com> | 2015-05-31 00:54:13 -0300 |
commit | 5130d68b729d90e90c8d70d8a7faac0d9c60c409 (patch) | |
tree | 6506342e26c03d4b7d76bb9ef6634228811a5dd8 | |
parent | b6bc845d06544a94f4466110b7e97d3ab1fb8ad9 (diff) | |
download | highline-5130d68b729d90e90c8d70d8a7faac0d9c60c409.tar.gz |
Remove Question#in_range? #valid_answer? and #convert parameters. Use self.answer as default.
-rwxr-xr-x | lib/highline.rb | 6 | ||||
-rwxr-xr-x | lib/highline/question.rb | 32 |
2 files changed, 19 insertions, 19 deletions
diff --git a/lib/highline.rb b/lib/highline.rb index 8cdb7f9..784a93b 100755 --- a/lib/highline.rb +++ b/lib/highline.rb @@ -531,11 +531,11 @@ class HighLine begin question.answer = question.get_response_or_default(self) - raise NotValidQuestionError unless question.valid_answer?(question.answer) + raise NotValidQuestionError unless question.valid_answer? - question.answer = question.convert(question.answer) + question.answer = question.convert - if question.in_range?(question.answer) + if question.in_range? if question.confirm # need to add a layer of scope to ask a question inside a # question, without destroying instance data diff --git a/lib/highline/question.rb b/lib/highline/question.rb index 4d1069e..96f2df8 100755 --- a/lib/highline/question.rb +++ b/lib/highline/question.rb @@ -311,19 +311,19 @@ class HighLine # This method throws ArgumentError, if the conversion cannot be # completed for any reason. # - def convert( answer_string ) - return answer_string unless @answer_type + def convert + return answer unless @answer_type if [::String, HighLine::String].include?(@answer_type) - HighLine::String(answer_string) + HighLine::String(answer) elsif [Float, Integer, String].include?(@answer_type) - Kernel.send(@answer_type.to_s.to_sym, answer_string) + Kernel.send(@answer_type.to_s.to_sym, answer) elsif @answer_type == Symbol - answer_string.to_sym + answer.to_sym elsif @answer_type == Regexp - Regexp.new(answer_string) + Regexp.new(answer) elsif @answer_type.is_a?(Array) or [File, Pathname].include?(@answer_type) - answer = choices_complete(answer_string) + self.answer = choices_complete(answer) if @answer_type.is_a?(Array) answer.last elsif @answer_type == File @@ -332,9 +332,9 @@ class HighLine Pathname.new(File.join(@directory.to_s, answer.last)) end elsif @answer_type.respond_to? :parse - @answer_type.parse(answer_string) + @answer_type.parse(answer) elsif @answer_type.is_a?(Proc) - @answer_type[answer_string] + @answer_type[answer] end end @@ -381,10 +381,10 @@ class HighLine # _in_ attribute. Otherwise, +false+ is returned. Any +nil+ attributes # are not checked. # - def in_range?( answer_object ) - (@above.nil? or answer_object > @above) and - (@below.nil? or answer_object < @below) and - (@in.nil? or @in.include?(answer_object)) + def in_range? + (@above.nil? or answer > @above) and + (@below.nil? or answer < @below) and + (@in.nil? or @in.include?(answer)) end # @@ -457,10 +457,10 @@ class HighLine # It's important to realize that an answer is validated after whitespace # and case handling. # - def valid_answer?( answer_string ) + def valid_answer? @validate.nil? or - (@validate.is_a?(Regexp) and answer_string =~ @validate) or - (@validate.is_a?(Proc) and @validate[answer_string]) + (@validate.is_a?(Regexp) and answer =~ @validate) or + (@validate.is_a?(Proc) and @validate[answer]) end # |