class TTY::Prompt::Question::Checks::CheckRange
Check if value is within range
Public Class Methods
call(question, value)
click to toggle source
# File lib/tty/prompt/question/checks.rb, line 38 def self.call(question, value) if !question.in? || (question.in? && question.in.include?(cast(value))) [value] else tokens = {value: value, in: question.in} [value, question.message_for(:range?, tokens)] end end
cast(value)
click to toggle source
# File lib/tty/prompt/question/checks.rb, line 28 def self.cast(value) if float?(value) value.to_f elsif int?(value) value.to_i else value end end
float?(value)
click to toggle source
# File lib/tty/prompt/question/checks.rb, line 20 def self.float?(value) !/[-+]?(\d*[.])?\d+/.match(value.to_s).nil? end
int?(value)
click to toggle source
# File lib/tty/prompt/question/checks.rb, line 24 def self.int?(value) !/^[-+]?\d+$/.match(value.to_s).nil? end