Class: Irc::Bot::Config::ArrayValue

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

Instance Attribute Summary

Attributes inherited from Value

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

Instance Method Summary collapse

Methods inherited from Value

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

Constructor Details

#initialize(key, params) ⇒ ArrayValue

Returns a new instance of ArrayValue.



166
167
168
169
170
171
172
# File 'lib/rbot/config.rb', line 166

def initialize(key, params)
  super
  @validate_item = params[:validate_item]
  @validate ||= Proc.new do |v|
    !v.find { |i| !validate_item(i) }
  end
end

Instance Method Details

#add(val) ⇒ Object



184
185
186
187
188
189
190
191
192
# File 'lib/rbot/config.rb', line 184

def add(val)
  newval = self.get.dup
  unless newval.include? val
    newval << val
    validate_item(val) or raise ArgumentError, "invalid item: #{val}"
    validate(newval) or raise ArgumentError, "invalid value: #{newval.inspect}"
    set(newval)
  end
end

#parse(string) ⇒ Object



178
179
180
# File 'lib/rbot/config.rb', line 178

def parse(string)
  string.split(/,\s+/)
end

#rm(val) ⇒ Object

Raises:

  • (ArgumentError)


193
194
195
196
197
# File 'lib/rbot/config.rb', line 193

def rm(val)
  curval = self.get
  raise ArgumentError, "value #{val} not present" unless curval.include?(val)
  set(curval - [val])
end

#to_sObject



181
182
183
# File 'lib/rbot/config.rb', line 181

def to_s
  get.join(", ")
end

#validate_item(item) ⇒ Object



174
175
176
# File 'lib/rbot/config.rb', line 174

def validate_item(item)
  validate(item, @validate_item)
end