Class: HammerCLI::Options::Normalizers::Bool
- Inherits:
-
AbstractNormalizer
- Object
- AbstractNormalizer
- HammerCLI::Options::Normalizers::Bool
- Defined in:
- lib/hammer_cli/options/normalizers.rb
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from AbstractNormalizer
Class Method Details
.common_description ⇒ Object
236 237 238 |
# File 'lib/hammer_cli/options/normalizers.rb', line 236 def common_description _('One of %s') % ['true/false', 'yes/no', '1/0'].join(', ') end |
.completion_type ⇒ Object
232 233 234 |
# File 'lib/hammer_cli/options/normalizers.rb', line 232 def completion_type :boolean end |
Instance Method Details
#allowed_values ⇒ Object
241 242 243 |
# File 'lib/hammer_cli/options/normalizers.rb', line 241 def allowed_values ['yes', 'no', 'true', 'false', '1', '0'] end |
#complete(value) ⇒ Object
256 257 258 |
# File 'lib/hammer_cli/options/normalizers.rb', line 256 def complete(value) allowed_values.map { |v| v + ' ' } end |
#completion_type ⇒ Object
260 261 262 |
# File 'lib/hammer_cli/options/normalizers.rb', line 260 def completion_type super.merge({ values: allowed_values }) end |
#format(bool) ⇒ Object
245 246 247 248 249 250 251 252 253 254 |
# File 'lib/hammer_cli/options/normalizers.rb', line 245 def format(bool) bool = bool.to_s if bool.downcase.match(/^(true|t|yes|y|1)$/i) return true elsif bool.downcase.match(/^(false|f|no|n|0)$/i) return false else raise ArgumentError, _('Value must be one of %s.') % ['true/false', 'yes/no', '1/0'].join(', ') end end |