Class: I18n::Tasks::Command::OptionParsers::Enum::Parser
- Inherits:
-
Object
- Object
- I18n::Tasks::Command::OptionParsers::Enum::Parser
- Defined in:
- lib/i18n/tasks/command/option_parsers/enum.rb
Constant Summary collapse
- DEFAULT_ERROR =
proc do |invalid, valid| I18n.t('i18n_tasks.cmd.enum_opt.invalid', invalid: invalid, valid: valid * ', ') end
Instance Method Summary collapse
- #call(value) ⇒ Object
-
#initialize(valid, error_message = DEFAULT_ERROR) ⇒ Parser
constructor
A new instance of Parser.
Constructor Details
#initialize(valid, error_message = DEFAULT_ERROR) ⇒ Parser
Returns a new instance of Parser.
12 13 14 15 |
# File 'lib/i18n/tasks/command/option_parsers/enum.rb', line 12 def initialize(valid, = DEFAULT_ERROR) @valid = valid.map(&:to_s) @error_message = end |
Instance Method Details
#call(value) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/i18n/tasks/command/option_parsers/enum.rb', line 17 def call(value, *) return @valid.first unless value.present? if @valid.include?(value) value else fail CommandError, @error_message.call(value, @valid) end end |