Class: Irc::Bot::Config::EnumValue

Inherits:
Value show all
Defined in:
lib/rbot/config.rb

Instance Attribute Summary

Attributes inherited from Value

#auth_path, #key, #manager, #order, #requires_rescan, #requires_restart, #type, #wizard

Instance Method Summary collapse

Methods inherited from Value

#default, #get, #set, #set_string, #to_s, #unset

Constructor Details

#initialize(key, params) ⇒ EnumValue

Returns a new instance of EnumValue.



201
202
203
204
# File 'lib/rbot/config.rb', line 201

def initialize(key, params)
  super
  @values = params[:values]
end

Instance Method Details

#descObject



218
219
220
# File 'lib/rbot/config.rb', line 218

def desc
  _("%{desc} [valid values are: %{values}]") % {:desc => @desc, :values => values.join(', ')}
end

#parse(string) ⇒ Object



212
213
214
215
216
217
# File 'lib/rbot/config.rb', line 212

def parse(string)
  unless values.include?(string)
    raise ArgumentError, "invalid value #{string}, allowed values are: " + values.join(", ")
  end
  string
end

#valuesObject



205
206
207
208
209
210
211
# File 'lib/rbot/config.rb', line 205

def values
  if @values.instance_of?(Proc)
    return @values.call(@manager.bot)
  else
    return @values
  end
end