Module: TTY::Prompt::Converters

Extended by:
ConverterDSL
Defined in:
lib/tty/prompt/converters.rb

Constant Summary collapse

TRUE_VALUES =
/^(t(rue)?|y(es)?|on|1)$/i.freeze
FALSE_VALUES =
/^(f(alse)?|n(o)?|off|0)$/i.freeze
SINGLE_DIGIT_MATCHER =
/^(?<digit>\-?\d+(\.\d+)?)$/.freeze
DIGIT_MATCHER =
/^(?<open>-?\d+(\.\d+)?)
 \s*(?<sep>(\.\s*){2,3}|-|,)\s*
 (?<close>-?\d+(\.\d+)?)$
/x.freeze
LETTER_MATCHER =
/^(?<open>\w)
 \s*(?<sep>(\.\s*){2,3}|-|,)\s*
 (?<close>\w)$
/x.freeze

Class Method Summary collapse

Methods included from ConverterDSL

convert, converter, converter_registry

Class Method Details

.cast_to_num(num) ⇒ Integer, ...

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Convert string number to integer or float

Returns:


92
93
94
95
# File 'lib/tty/prompt/converters.rb', line 92

def cast_to_num(num)
  ([convert(:int, num), convert(:float, num)] - [Const::Undefined]).first ||
    Const::Undefined
end