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.
160 161 162 |
# File 'lib/hammer_cli/options/normalizers.rb', line 160 def initialize(allowed_values) @allowed_values = allowed_values end |
Instance Attribute Details
#allowed_values ⇒ Object (readonly)
Returns the value of attribute allowed_values.
158 159 160 |
# File 'lib/hammer_cli/options/normalizers.rb', line 158 def allowed_values @allowed_values end |
Instance Method Details
#complete(value) ⇒ Object
181 182 183 |
# File 'lib/hammer_cli/options/normalizers.rb', line 181 def complete(value) Completer::finalize_completions(@allowed_values) end |
#description ⇒ Object
164 165 166 |
# File 'lib/hammer_cli/options/normalizers.rb', line 164 def description _("Possible value(s): %s") % quoted_values end |
#format(value) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/hammer_cli/options/normalizers.rb', line 168 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 |