Class: HammerCLI::Options::Normalizers::Enum
- Inherits:
-
AbstractNormalizer
- Object
- AbstractNormalizer
- HammerCLI::Options::Normalizers::Enum
- Defined in:
- lib/hammer_cli/options/normalizers.rb
Instance Attribute Summary collapse
-
#allowed_values ⇒ Object
readonly
Returns the value of attribute allowed_values.
Instance Method Summary collapse
- #complete(value) ⇒ Object
- #description ⇒ Object
- #format(value) ⇒ Object
-
#initialize(allowed_values) ⇒ Enum
constructor
A new instance of Enum.
Constructor Details
#initialize(allowed_values) ⇒ Enum
Returns a new instance of Enum.
235 236 237 |
# File 'lib/hammer_cli/options/normalizers.rb', line 235 def initialize(allowed_values) @allowed_values = allowed_values end |
Instance Attribute Details
#allowed_values ⇒ Object (readonly)
Returns the value of attribute allowed_values.
233 234 235 |
# File 'lib/hammer_cli/options/normalizers.rb', line 233 def allowed_values @allowed_values end |
Instance Method Details
#complete(value) ⇒ Object
256 257 258 |
# File 'lib/hammer_cli/options/normalizers.rb', line 256 def complete(value) Completer::finalize_completions(@allowed_values) end |
#description ⇒ Object
239 240 241 |
# File 'lib/hammer_cli/options/normalizers.rb', line 239 def description _("Possible value(s): %s") % quoted_values end |
#format(value) ⇒ Object
243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/hammer_cli/options/normalizers.rb', line 243 def format(value) if @allowed_values.include? value value else if allowed_values.count == 1 msg = _("Value must be %s.") % quoted_values else msg = _("Value must be one of %s.") % quoted_values end raise ArgumentError, msg end end |