lib/tty/coercer/boolean.rb in tty-0.0.11 vs lib/tty/coercer/boolean.rb in tty-0.1.0

- old
+ new

@@ -1,39 +1,36 @@ -# -*- encoding: utf-8 -*- +# encoding: utf-8 module TTY class Coercer - # A class responsible for boolean type coercion class Boolean - # Coerce value to boolean type including range of strings such as # # @param [Object] value # # @example # coerce("True") # => true # # other values coerced to true are: # 1, t, T, TRUE, true, True, y, Y, YES, yes, Yes # - # coerce("False") # => false + # @example + # coerce("False") # => false # # other values coerced to false are: # 0, f, F, FALSE, false, False, n, N, No, no, No # # @api public def self.coerce(value) case value.to_s - when %r/^(yes|y|t(rue)?|1)$/i + when /^(yes|y|t(rue)?|1)$/i return true - when %r/^(no|n|f(alse)?|0)$/i + when /^(no|n|f(alse)?|0)$/i return false else - raise TypeError, "Expected boolean type, got #{value}" + fail TypeError, "Expected boolean type, got #{value}" end end - end # Boolean - end # Coercer end # TTY