Class: Wpxf::BooleanOption
- Defined in:
- lib/wpxf/core/opts/boolean_option.rb
Overview
A boolean option.
Instance Attribute Summary
Attributes inherited from Option
#advanced, #default, #desc, #enums, #evasion, #name, #regex, #required
Instance Method Summary collapse
-
#false?(value) ⇒ Boolean
True if the value is a false boolean value.
-
#normalize(value) ⇒ Boolean
A normalized value to conform with the type that.
-
#true?(value) ⇒ Boolean
True if the value is a true boolean value.
-
#valid?(value) ⇒ Boolean
Check if the specified value is valid in the context of this option.
Methods inherited from Option
#advanced?, #display_value, #empty?, #empty_required_value?, #evasion?, #initialize, #required?, #update_optional_attributes, #value?
Constructor Details
This class inherits a constructor from Wpxf::Option
Instance Method Details
#false?(value) ⇒ Boolean
Returns true if the value is a false boolean value.
33 34 35 |
# File 'lib/wpxf/core/opts/boolean_option.rb', line 33 def false?(value) !true?(value) end |
#normalize(value) ⇒ Boolean
Returns a normalized value to conform with the type that. the option is conveying.
21 22 23 |
# File 'lib/wpxf/core/opts/boolean_option.rb', line 21 def normalize(value) valid?(value) && !value.to_s.match(/^(y|yes|t|1|true)$/i).nil? end |
#true?(value) ⇒ Boolean
Returns true if the value is a true boolean value.
27 28 29 |
# File 'lib/wpxf/core/opts/boolean_option.rb', line 27 def true?(value) normalize(value) end |
#valid?(value) ⇒ Boolean
Check if the specified value is valid in the context of this option.
10 11 12 13 14 15 16 |
# File 'lib/wpxf/core/opts/boolean_option.rb', line 10 def valid?(value) return false if empty_required_value?(value) return true if !required? && empty?(value) pattern = /^(y|yes|n|no|t|f|0|1|true|false)$/i value?(value) && !value.to_s.match(pattern).nil? end |