Sha256: ed349df27fd0266d98a37ca0adc07596476eeabca0fe308232924f45e80afffa

Contents?: true

Size: 472 Bytes

Versions: 3

Compression:

Stored size: 472 Bytes

Contents

module OptParseValidator
  # Implementation of the Boolean Option
  class OptBoolean < OptBase
    TRUE_PATTERN  = /\A(true|t|yes|y|1)\z/i.freeze
    FALSE_PATTERN = /\A(false|f|no|n|0)\z/i.freeze

    # @return [ Boolean ]
    def validate(value)
      value = value.to_s

      return true if value.match(TRUE_PATTERN)
      return false if value.match(FALSE_PATTERN)

      raise Error, 'Invalid boolean value, expected true|t|yes|y|1|false|f|no|n|0'
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
opt_parse_validator-0.0.17.0 lib/opt_parse_validator/opts/boolean.rb
opt_parse_validator-0.0.16.6 lib/opt_parse_validator/opts/boolean.rb
opt_parse_validator-0.0.16.5 lib/opt_parse_validator/opts/boolean.rb