Class: OptParseValidator::OptBoolean

Inherits:
OptBase
  • Object
show all
Defined in:
lib/opt_parse_validator/opts/boolean.rb

Overview

Implementation of the Boolean Option

Constant Summary collapse

TRUE_PATTERN =
/\A(true|t|yes|y|1)\z/i.freeze
FALSE_PATTERN =
/\A(false|f|no|n|0)\z/i.freeze

Instance Attribute Summary

Attributes inherited from OptBase

#attrs, #option, #required

Instance Method Summary collapse

Methods inherited from OptBase

#advanced?, #alias?, #append_help_messages, #choices, #default, #help_message_for_default, #help_messages, #initialize, #normalize, #required?, #required_unless, #to_long, #to_s, #to_sym, #value_if_empty

Constructor Details

This class inherits a constructor from OptParseValidator::OptBase

Instance Method Details

#validate(value) ⇒ Boolean

Returns:

  • (Boolean)

Raises:



10
11
12
13
14
15
16
17
# File 'lib/opt_parse_validator/opts/boolean.rb', line 10

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